Support » Fixing WordPress » Conditional tag in archives: how to tell if category is child of another?

  • I’m creating an archive page for a website.

    I want to change the header of the page according to the type of archive displayed.

    For example

    <?php if (is_category()) { ?>
    <h2><?php single_cat_title(); ?></h2>; } ?>

    and then add other conditionals… if is_author, if is_year, etc., each one gets a different title between <h2> tag

    however I also want to change the <h2> title according to the category that is displayed and all the child categories of that category. Silly example: for category “banana” or “apple”, both child categories of “fruit” i might want something like <h2>Fruit type: <?php single_cat_title(); ?></h2>; ?> ; while for categories under the parent category “vegetables” I want to display <h2>Vegetable: <?php single_cat_title(); ?></h2>; ?> etc… I hope this is clear

    if I specify in is_category() a category, it considers only that category and not child categories – and there’s no conditional tag like is_categoryparent or similar

    how to achieve what I want to do?

    thanks a lot

  • The topic ‘Conditional tag in archives: how to tell if category is child of another?’ is closed to new replies.