In my category.php, I've been using a conditional statement to select specific sidebars for specific categories or groups of categories, like this:
<?php if (is_category( array( 'cheddar', 'swiss'))) {
get_sidebar('cheese');
} else
if (is_category( array( 'apples', 'cherries', ))) {
get_sidebar('fruit');
} else {
get_sidebar();
} ?>
Is there a way to call a sidebar to be used with a category and all of that category's children?
Try it with:
$current_cat = get_query_var('cat');
if(is_category(3) || cat_is_ancestor_of( 3, $current_cat )) {
// get sidebar for category 3 and all of its children
}
After I posted I found this description of how to use a post_is_in_descendant_category function.
cat_is_ancestor_of looks useful. Thank you!
I need to make some test cases to feel through how practical application of cat_is_ancestor_of is different from post_is_in_descendant_category. Interesting.
you could always do something like this.....
if ( is_category('catgory1') || is_category('category2) {
get_sidebar('sidebar1');
}
elseif ( is_category('category3') {
get_sidebar('sidebar2')
}
else {
get_sidebar('sidebar3')
}
the || means OR in PHP.