Support » Theme: Customizr » How can we list posts from single category on posts page?

  • Resolved Keith Ratner

    (@rats1966)


    On the ‘Posts Page’ selected under ‘Front Page’ options, is there a snippet available to force that page to only display posts from a specific category, or even multiple categories?

Viewing 4 replies - 1 through 4 (of 4 total)
  • add_filter('pre_get_posts', 'limit_homepage_posts');
    function limit_homepage_posts($query) {
    	if ( $query->is_home() && $query->is_main_query() )
    		$query->set( 'cat', 'X,Y' );
    	}

    Replace X,Y with category ids. Or, if you want to use slugs, use

    $query->set( 'category_name', 'slug1,slug2' );

    This function (and the preceding filter) should go in functions.php of your child theme.

    Perfect. Thanks!

    Hi I am a bit confuse on how the filter function. Could you elaborate a little bit more please.

    Did I need to create a new page with the same nae of category?

    You don’t need to create a template. The function above filters the posts displayed on homepage.

    More on how filters work in WP here. It’s what makes WP flexible.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can we list posts from single category on posts page?’ is closed to new replies.