1
votes

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?

3

3 Answers

1
votes

The actual category id of a category archive is in the global $cat.

if(is_category()){
  global $cat;
  if($cat == '28'){
    //do stuff here
}
0
votes

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.

0
votes

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

     }

}