Refer Link for Your Knowledge Template Hiearchy for a more detailed break down of how WordPress chooses the template
For a taxonomy term slug (‘sports’ your example) in the taxonomy (e.g. ‘News’) WordPress will try to use the following
templates (in this order)
taxonomy-{taxonomy}-{slug}.php
taxonomy-{taxonomy}.php
taxonomy.php
archive.php
index.php
Modify Your texonomy Code snippet below :
function my_post_type() {
$args = array(
'labels' => array(
'name' => 'News',
'singular_name' => 'News',
'add_new' => 'Add New News',
'add_new_item' => 'Add New News',
'edit_item' => 'Edit News',
'new_item' => 'New News',
'all_items' => 'All News',
'view_item' => 'View News',
'search_items' => 'Search News',
'not_found' => 'No News Found',
'not_found_in_trash' => 'No News found in Trash',
'parent_item_colon' => '',
'menu_name' => 'News',
),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-admin-site-alt3',
'supports' => array('title','editor','thumbnail'),
'capability_type' => 'post',
);
register_post_type('news', $args);
}
add_action('init', 'my_post_type');
function my_taxonomy() {
$args = array(
'labels' => array(
'name' => 'News Category',
'singular_name' => 'News Category',
),
'public' => true,
'hierarchical' => true,
);
register_taxonomy('news_cat', array('news'),$args);
}
add_action('init', 'my_taxonomy');
For your ‘sports’,’games’,’politics ‘ taxonomy term page, WordPress will use
Put this file in your theme root directory
taxonomy-news_cat-sports.php
taxonomy-news_cat-games.php
taxonomy-news_cat-politics.php
Permalinks
You have also specified an url rewrite, so assuming the rewrite rules have been flushed and there isn’t a clash, the following should also work
www.example.com/news_cat/games
Note : Don’t Forget To update Permalinks Otherwise Categoty term page redirect to 404 page
taxonomy-news_cat-sports.php
<?php
get_header();
?>
<div id="content-sidebar-wrap">
<div class="wrap">
<main class="content">
<?php
$case_cat_slug = get_queried_object()->slug;
$case_cat_name = get_queried_object()->name;
?>
<h2><?php echo $case_cat_name; ?></h2>
<?php
$al_tax_post_args = array(
'post_type' => 'news', // Your Post type Name that You Registered
'posts_per_page' => 999,
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'news_cat',
'field' => 'slug',
'terms' => $case_cat_slug
)
)
);
$al_tax_post_qry = new WP_Query($al_tax_post_args);
if($al_tax_post_qry->have_posts()) :
while($al_tax_post_qry->have_posts()) :
$al_tax_post_qry->the_post();
echo '<div class="post-excerpt">';
?>
<h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink(); ?>" class="entry-title-link"><?php the_title(); ?></a></h2>
<div class="entry-content"> <?php the_title(); ?> </div>
</div>
<?php
endwhile;
endif;
?>
</main>
</div>
</div>
<?php
get_footer(); ?>