Show only posts from one category

Hi,

Is it possible to show only posts from one category in the standard posts list page?

Greetz,
Bernd

Hi @bernyboy,

I hope you are well today and thank you for your question.

Yes you can achieve this by adding the following code in the functions.php file of child theme that causes the home page to display posts only from one category.

function my_home_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '123' );
    }
}
add_action( 'pre_get_posts', 'my_home_category' );

Change the category id 123 in the above code with the category id from which you want to display the posts.

Best Regards,
Movin

Thanks, Movin!

I’m not a Wordpress pro, but with your codex child theme link I think I can handle it! It’s not that hard to do, it seems. I let you know as it works!

Greetzz,
BernyBoy

Hi, Movin

Works like a charm! Thanks a lot!

Should this be a nice function in th user interface? Espescially because the slider needs sticky posts and you don’t want those posts in your blog list.

Best Regards,
BernyBoy

You are most welcome here :slight_smile:

Yes we will consider this as a feature request to be implemented in the future version of theme.

Hi, Team!
A very good 2016 for you all, and keep doing the good work!

Movin told me a solution for showing only posts from one catagory in the blog. See thread above. I have implemented this in a child-theme. This worked perfectly.
After updating the theme all the posts are shown in the blog. The .css from the child theme still works.
Any solutions?

Thanks in advance,
Bernd Bosma

Hi Bernd Bosma,

Happy New Year 2016 :slight_smile:

Could you please share me your child theme so that i can test it on my test site and troubleshot the issue?

Regards,
Movin