• Searched way too long today, I give up. I am trying to find a way to detect a category and it’s subcategories, something like the following:

    if ( is_category( array( 'news','whatever', 'something else' ) ) || is_subcategory('news', 'another cat', 'etc') )

    I’m trying to show specific content for categories and their subcategories, on the category.php template.

    I know there is no such thing as is_subcategory, but there certainly should be. Anyone know of a trick to make this work?

    Thanks~!

    • This topic was modified 2 years, 7 months ago by t-p. Reason: Moved to Fixing WordPress from Developing with WordPress
Viewing 1 replies (of 1 total)
  • Hello @malawimama

    Try using the code given below and it will definitely help.

    if ( is_category( array( 'news','whatever', 'something else', 'news', 'another cat', 'etc' ) ) {
      // do something here
    }

    Adding the sub-category slug to the array of ‘is_category’. That will work for the sub-category too.

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional if is subcategory of x category?’ is closed to new replies.