WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] conditional tag to find out if the category archive is a child of ... (3 posts)

  1. piedro
    Member
    Posted 4 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Something like:

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

    should work within a category template file.

  3. piedro
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic