Based on WordPress template hierarchy, categories are displayed using the category.php
template. So in other to display your preferred category, you’ll need to create a category.php
file, and use the query below:
$cat_query = new WP_Query(
array(
'post_type' => 'post',
'cat' => $cat, //WordPress global for getting the current category
'posts_per_page' => 5,
)
);
And then you loop like so:
if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ): $cat_query->the_post();