Add the following code to your WordPress theme’s function.php file, or a functionality plugin to create a custom Shop Post Type For Your Online Store.
* Note – If you are using a Shop plugin like WooCommerce, this wouldn’t be necessary. The use scenario for this code is if you have an external shop like 1Shopping Cart or use PayPal Links.
/** Custom Shop Post Types */
function be_shop_template( $template ) {
if( is_tax( array( 'shop_category', 'shop_tag' ) ) )
$template = get_query_template( 'archive-shop' );
return $template;
}
add_filter( 'template_include', 'be_shop_template' );
/** Add 'page-attributes' to shop Post Type
* @param array $args, arguments passed to register_post_type
* @return array $args */
function be_shop_post_type_args( $args ) {
$args['supports'][] = 'page-attributes';
return $args;
}
add_filter( 'shopposttype_args', 'be_shop_post_type_args' );
/** Sort projects by menu order
*
*/
function be_shop_query( $query ) {
if( $query->is_main_query() && !is_admin() && ( is_post_type_archive( 'shop' ) || is_tax( array( 'shop_category', 'shop_tag' ) ) ) ) {
$query->set( 'posts_per_page', '25' );
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'be_shop_query' );
/** remove_action( 'genesis_after_post', 'genesis_get_comments_template' ); */
add_action('get_header','cd_change_genesis_sidebar');
function cd_change_genesis_sidebar() {
if ( is_singular('shop') || is_page( array( 1, 2, 3, 4 )) || is_post_type_archive('shop') ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'cd_do_sidebar' );
}
}
is_page( array( 1, 2, 3, 4 )) where 1, 2, 3, and 4 are the IDs of the pages that should use the custom post type.
//Function to output my custom sidebar
function cd_do_sidebar() {
dynamic_sidebar( 'shop-single-sidebar' );
}
Share Your Two Cents