0

I just want to display a section in the parent category. And I want to display another section in the child category. How to do it?

      if ( is_category() ) {
          get_template_part( 'template-parts/banner/tab-1' , 'xcde' ); 
        } else {
           get_template_part( 'template-parts/banner/tab-2' , 'xcde' ); 
       ]
    

1 Answer 1

0

On your category template you can use get_queried_object() to get the current WP_Term object. From that you can check the parent property, which is 0, if it is a parent, or some integer, if it is a child term as it returns the parent term's ID.

$current_term = get_queried_object();
if ( $current_term->parent ) { 
    // child term
} else {
    // parent term
}
1
  • Thank you । It's working.
    – cholonto
    Commented May 16, 2021 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.