WordPress.org

Support

Support » Themes and Templates » [Resolved] conditional tag to find out if the category archive is a child of …

[Resolved] conditional tag to find out if the category archive is a child of …

  • Hello!

    Another problem:
    On category archives I want to use different sidebars for different main categories.

    So I want to ask the database if the current category archive is a sub-category of the main category with the ID=14.

    I found this code

    <?php if (cat_is_ancestor_of( 14 , $current )); ?>

    But it doesn’t work. Because I don’t understand how to get the $current variable.

    plz, more help appreciated,
    thx, piedro

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi
    Forum Moderator

    @esmi

    Something like:

    <?php $cat_id = get_query_var('cat');
    if (cat_is_ancestor_of( 14 , $cat_id )); ?>

    should work within a category template file.

    Hi esmi!

    thx alot!

    <?php $cat_id = get_query_var('cat');
    if (cat_is_ancestor_of( 14 , $cat_id )) : ?>

    Just a “:” instead of “;” at the end of the second line.

    Works perfect now!

    You rock!
    p.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] conditional tag to find out if the category archive is a child of …’ is closed to new replies.