WordPress.org

Ready to get started?Download WordPress

Forums

Parent category identification problem (1 post)

  1. nims
    Member
    Posted 2 years ago #

    I want to display a snippet when post is in specific categories.
    I have categories A, B , C, D and want to display "How r u" when posts belong to Categories A and B. Also, if the post belongs to sub-categories in A and B.

    I used the code

    if ( in_category(array('A,'B')))
    {
    echo "How r u";
    	}

    It works fine but if the post is in sub-category of A or B it does not work. I do not wish to hardcode the sub-category names as I might add few more sub-categories.
    Is there a way I can check direct parent and display what I want.

Topic Closed

This topic has been closed to new replies.

About this Topic