• Resolved paa1605

    (@paa1605)


    Hi folks,

    I’m trying to complete my category.php file. I would like to be able to write a conditional tag that asks if we are on a particular category page, or one of its child category pages, and if so, do this. For example, is this the category page for ‘clothes’, or one of its child categories such as ‘childrens clothes’? If so, do this, or else.

    Can anyone help me in writing code that would allow me to do this? Thanks.

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

    (@keesiemeijer)

    Conditional Tags

    Use it like this:

    <?php
    if ( in_category( '11' ) || post_is_in_descendant_category( '11' ) ) {
    	// do stuff
    }
    ?>
    Thread Starter paa1605

    (@paa1605)

    Thanks for the reply.

    I think the query needs to be is_category rather than in_category as i want a certain parent category and its child categories to have the same layout, hence the conditional tag. The ‘in_category’ tag seems to relate to what posts are shown on specific category archives, not the layout of each archive page. Do you know how to check for this instead?

    Thread Starter paa1605

    (@paa1605)

    I appear to have found a solution! I added this code into my category.php file and it now works

    <?php if (cat_is_ancestor_of(4, $cat) or is_category(4)) { ?>
    <? } ?>

    Thanks for the help anyway.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional help for category.php’ is closed to new replies.