0

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' );
  • 2
    Can't you add a category-live-score.php, category-standings.php etc to your theme? – kero Jun 4 at 11:45
  • i can...but would have love the link to be ../sports/sub-categories – John4Peace Jun 4 at 11:56
  • That doesn't change the link at all – kero Jun 4 at 12:09
  • 2
    Worked perfectly...thanks – John4Peace Jun 4 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.