admin管理员组文章数量:1130349
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
Share Improve this question edited Jan 4, 2019 at 9:10 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Jan 4, 2019 at 9:03 Minyak IkanMinyak Ikan 112 bronze badges 1- You can't do this with a single query. You will need to get a list of categories, loop over them, and query 1 post from each, separately. – Jacob Peattie Commented Jan 4, 2019 at 9:20
1 Answer
Reset to default 0As 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:
- Install and activate the plugin.
- Head to Appearance > Widgets. Add Recent Posts Extended widget to your sidebar.
- The widget menu will expand to show its settings. Here, you can choose your desired category and specify the number of posts to show.
- Finally, click on the Save button to store your widget settings.
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
Share Improve this question edited Jan 4, 2019 at 9:10 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Jan 4, 2019 at 9:03 Minyak IkanMinyak Ikan 112 bronze badges 1- You can't do this with a single query. You will need to get a list of categories, loop over them, and query 1 post from each, separately. – Jacob Peattie Commented Jan 4, 2019 at 9:20
1 Answer
Reset to default 0As 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:
- Install and activate the plugin.
- Head to Appearance > Widgets. Add Recent Posts Extended widget to your sidebar.
- The widget menu will expand to show its settings. Here, you can choose your desired category and specify the number of posts to show.
- Finally, click on the Save button to store your widget settings.
本文标签: categoriesDisplaying just one newcurrent post per category in homepage
版权声明:本文标题:categories - Displaying just one newcurrent post per category in homepage 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749044630a2307670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论