I want to displaying only one new/current post per category in homepage. For example, there is 3 post with category A, and i want the old post from category A is replaced with the new post from category A in homepage, and the old post is just gone but not deleted. This also same for other categories.
I'm using pre_get_posts
to approach this, but mine is just display one category only and the other is not.
Here's my code
function my_home_category( $query ) {
if ( $query->is_home() ) {
$query->set( 'cat', -1 );
$query->set( 'posts_per_page', -1);
}
}
add_action( 'pre_get_posts', 'my_home_category' );
I know my code is not good, and i gladly appreciated any help that come to mind. thanks
I want to displaying only one new/current post per category in homepage. For example, there is 3 post with category A, and i want the old post from category A is replaced with the new post from category A in homepage, and the old post is just gone but not deleted. This also same for other categories.
I'm using pre_get_posts
to approach this, but mine is just display one category only and the other is not.
Here's my code
function my_home_category( $query ) {
if ( $query->is_home() ) {
$query->set( 'cat', -1 );
$query->set( 'posts_per_page', -1);
}
}
add_action( 'pre_get_posts', 'my_home_category' );
I know my code is not good, and i gladly appreciated any help that come to mind. thanks
As you are not comfortable with coding, you can try using Recent Posts Widget Extended plugin. It allows you to specify the number of posts per category that you want to be displayed.
Follow these steps: