admin管理员组

文章数量:1425742

Sports

  • live score
  • standings
  • Transfer

As seen above...the parent category is Sports with three subcategories (live score, standings and transfer)...Can each of these subcategories have a different custom category template...that is each subcategory with unique template

here is my code below...

// Different template for subcategories
function wpd_subcategory_template( $template ) {
    $cat        = get_queried_object();
    $children   = get_terms( $cat->taxonomy, array(
        'parent'     => $cat->term_id,
        'hide_empty' => false
    ) );

    if( ! $children ) {
        $template = locate_template( 'category-sports-livescores.php' );
    } elseif( 0 < $cat->category_parent ) {
        $template = locate_template( 'category-sports.php' );
    }

    return $template;
}
add_filter( 'category_template', 'wpd_subcategory_template' );

本文标签: categorieshow to give different template to each subcategory from same parent category