按类别排序,然后在Wordpress主页上按日期排序


Sort by category and then date on Wordpress homepage

我的Wordpress网站有多个自定义类别和帖子类型,所有这些都需要显示在主页博客上。但是我需要主页上的第一篇文章始终是特定类别的最新帖子。

例如,页面顶部的 pst 将始终是最新的"长颈鹿"类别;在它下方;按时间顺序排序的"海象"与"海鸥"和"玉米片"混合在一起

实现这一目标的最佳方法是什么?

无需两次

运行循环,粘性帖子是您的最佳选择。

否则:

...
$args = array(
 'orderby' => 'post_date',
 'category'=> 'giraffe',
 'numberposts'=> 1,
);
$latest_giraffe_post = get_posts( $args );    
... 

然后做你已经在做的事情