In Twitter a user asks,
Question! Can I used a custom category template for specific categories using conditional tags? #genesiswp #wordpress
— Melissa (@blushandjelly) September 16, 2016
This can be done using template_include
filter in WordPress.
Step 1
Create your custom template named say, template_custom-category.php in your child theme directory having the following:
<?php
// Force full width content
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
genesis();
You would need to place your custom code in between the opening PHP tag and closing genesis();
function. In the above example we are setting the width of content to be full i.e., no sidebar.
Step 2
Let’s apply the above template to “Category 1” and “Category 2” category archive pages. Add the following in child theme’s functions.php:
/**
* Template Redirect
* Use template_custom-category.php for specific category archives.
*/
add_filter( 'template_include', 'custom_category_template', 99 );
function custom_category_template( $template ) {
if ( is_category( array( 'category-1', 'category-2' ) ) ) {
$new_template = locate_template( array( 'template_custom-category.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
Replace category-1
and category-2
with the slugs of your desired categories.
That’s it. Now all the category archive pages in your Genesis site except the specified categories will use the default layout (content, content/sidebar, sidebar/content etc.) as set in the Genesis theme settings while the specified categories will use full content layout.
Note: When you edit the specified categories in the back end and apply a layout other than the default layout, then it will be used for the display trumping the code from Step 2.