Display Posts from a Specific Category on WordPress page
WordPress Twenty Fifteen Theme Tutorial to Show only one Category posts on home page and blog page.This code works in all WordPress themes.
Display posts from one category on page of your WordPress website is a really great idea.I implemented this code in one of my WordPress website (top engineering colleges) to show latest posts only from USA schools category.
Here's a code snippet to display only one category posts on a page.Paste the following code in your WordPress twenty fifteen child theme's functions.php file and replace the category ID number with your own category ID.This code will display one category posts in your WordPress blog/home page.
//category on home page
add_action( 'pre_get_posts', 'one_category_home_page' );
function one_category_home_page( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '6' );
}
}
Don't forget to replace category ID number 6 in the above code with your category ID, which you want to show all posts from that category only.