Support » Fixing WordPress » If article is in parent category

  • dompl

    (@dompl)


    Hi.

    I’m trying to change my template for child categories by defining parent category.

    I’ve tried this :

    <?php
    $category = get_the_category();
    if ($category->category_parent == 5) : ?>
    my template
    <?php endif ; ?>

    But it doesn’t seem to work.

    Any ides please?

    thank in advance.

Viewing 1 replies (of 1 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    $category is an array (even if you only have one category on your post); therefore try:

    <?php
    $category = get_the_category();
    if ($category[0]->category_parent == 5) : ?>
    my template
    <?php endif ; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘If article is in parent category’ is closed to new replies.