WordPress.org

Forums

If article is in parent category (2 posts)

  1. dompl
    Member
    Posted 4 years ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    $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 ; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.