2 Formatting, tags
source | link

I want to use different template for posts of all subcategory of one category. Below is the Code I am using :

add_filter( 'single_template', 'get_custom_cat_template' ) ;
function get_custom_cat_template( $single_template ) {
     global $post;
       if ( is_category( 'blog' ) || in_category( 'blog' ) ) {
          $single_template = dirname( __FILE__ ) . '/single-blog.php';
     }
  
    return $single_template;  
} 

add_filter( "single_template", "get_custom_cat_template" ) ;

Here "blog" is the category.This This code is working for parent category (blog) only.For For posts of subcategory, it is loading default single.phpsingle.php file.How

How can I change the code so that it works for all subcategories of parent category. Please help me.?

I want to use different template for posts of all subcategory of one category. Below is the Code I am using :

function get_custom_cat_template($single_template) {
     global $post;
       if(is_category('blog') || in_category('blog')){
          $single_template = dirname( __FILE__ ) . '/single-blog.php';
     }
     return $single_template; } 

add_filter( "single_template", "get_custom_cat_template" ) ;

Here "blog" is category.This code is working for parent category (blog) only.For posts of subcategory, it is loading default single.php file.How can I change the code so that it works for all subcategories of parent category. Please help me.

I want to use different template for posts of all subcategory of one category. Below is the Code I am using :

add_filter( 'single_template', 'get_custom_cat_template' ) ;
function get_custom_cat_template( $single_template ) {
    global $post;
    if ( is_category( 'blog' ) || in_category( 'blog' ) ) {
        $single_template = dirname( __FILE__ ) . '/single-blog.php';
    }
 
    return $single_template; 
}

Here "blog" is the category. This code is working for parent category (blog) only. For posts of subcategory, it is loading default single.php file.

How can I change the code so that it works for all subcategories of parent category?

1
source | link

Different template for posts of all subcategories of category

I want to use different template for posts of all subcategory of one category. Below is the Code I am using :

function get_custom_cat_template($single_template) {
     global $post;
       if(is_category('blog') || in_category('blog')){
          $single_template = dirname( __FILE__ ) . '/single-blog.php';
     }
     return $single_template; } 

add_filter( "single_template", "get_custom_cat_template" ) ;

Here "blog" is category.This code is working for parent category (blog) only.For posts of subcategory, it is loading default single.php file.How can I change the code so that it works for all subcategories of parent category. Please help me.