Support » Themes and Templates » Custom sidebar for category children?

  • 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'))) {
    } else
    if (is_category( array( 'apples', 'cherries', ))) {
    } else {
    } ?>

    Is there a way to call a sidebar to be used with a category and all of that category’s children?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer


    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) {
    elseif ( is_category('category3') {
    else {

    the || means OR in PHP.

    eable… I tried using your conditional statement but can’t seem to get it to work (I’m a newb to php).

    I replaced:
    <?php get_sidebar(); ?>
    <?php if (is_category( array( ‘jewel’, ‘lotus’))) {
    } else
    if (is_category( array( ‘almanac’ ))) {
    } else {
    } ?>

    Is there something I’m doing wrong, or something more I need to do?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom sidebar for category children?’ is closed to new replies.