I need if (is_category ( )) to display content ONLY on parent category, not on child category pages

I need to display an intro paragraph on an archive page that displays all posts in the parent and child categories. I’m adding the required content via a sidebar widget and I have code that displays it correctly.

if( is_category( '28' ) || get_sidebar('blog-intro'));

The problem is the side bar widget also displays on all child pages for category 28 => 28/a, 28/b,… I need it on just category 28. Any ideas on how I can filter that out?

Related posts

Leave a Reply

3 comments

  1. On further lowering of expectations, I think allowing the widget to display on all blog archive pages but not on single posts is acceptable.

    But I’m still curious about the answer.

  2. I’d look into get_category()

    If I recall correctly, $cat->parent_category() will return 0 if it’s a top level category

    So:

    if( get_query_var( 'cat' ) == 28 ) {
    
         $cat = get_category( 28 );
    
         if( ! $cat->parent_category() ) {
    
             // output content here
    
         }
    
    }