我对贴纸有问题。这是我的循环:
3,
'orderby' => 'date',
);
$query = new WP_Query($main_loop);
?>
have_posts()): ?>
have_posts()): $query->the_post();?>
// loop现在,当posts_per_page是3,我需要显示最大。2个粘性柱。所以:
当1粘的时候也有2条固定的帖子,当2粘的时候也有1条固定的帖子,当0粘粘的时候有3条固定的帖子。
我怎么发动汽车呢?
发布于 2018-10-02 09:56:54
编辑2:更新后的代码,以说明“也许没有粘贴的帖子”;)
编辑:我用帖子的数量做了个嘘声。修正了,现在应该按预期工作了。
您可以通过使用两个查询来完成这一任务。
count($stickiessliced),
'orderby' => 'date',
'post__in' => $stickiessliced,
'ignore_sticky_posts' => true
);
//only get sliced sticky posts, ignore everything else
$query = new WP_Query($sticky_loop);
//do the loop for the sticky posts
if ($query->have_posts()): ?>
have_posts()): $query->the_post();?>
// loop
$numposts,
'orderby' => 'date',
'post__not_in' => $stickies,
//replace $stickiessliced with $stickies to make sure that NO other stickies are queried (as is: the above queried stickies are ignored)
'ignore_sticky_posts' => true
);
$query = new WP_Query($main_loop);
//do the loop for the remaining posts to fill up
if ($query->have_posts()): ?>
have_posts()): $query->the_post();?>
// loop这应该是这样的:如果有0到2个粘性的帖子,他们会被查询,循环,然后1到3个“正常”的帖子被查询。如果有两个以上的粘性帖子,前两个是切片,然后再一个“正常”的帖子被查询。
编码愉快!
https://wordpress.stackexchange.com/questions/315680
复制相似问题