使用 caller_get_posts=1 使 WordPress 粘性帖子正常运行是行不通的
我正在制作一个特定的 single.php 模板。它使用 jQuery 滑块从一篇文章滑动到下一篇文章。为了首先显示正确的帖子,我必须使用 2 个循环 - 一个循环调用第一个帖子,然后另一个循环调用该类别中的所有其他帖子。
我确实喜欢这个(可能有点肮脏,我不是 PHP 大师)
<ul id="tour-items">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</li>
<?php endwhile; endif; ?>
<?php $briefingsposts = new WP_Query(array(
'caller_get_posts' => 1,
'category_name' => Briefings,
'offset' => 1
)); ?>
<?php while ($briefingsposts->have_posts()) : $briefingsposts->the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
但是,如果第一篇文章是置顶文章,则尽管有“offset”=>,它仍会在类别循环中重复。 1 我认为这是因为它正在执行粘性行为并将其自身粘在顶部。
我尝试过使用 'caller_get_posts' => 1 在数组中,但似乎没有任何区别。我不想排除粘性帖子,只是让它们表现正常。有没有一种方法可以在我的查询中工作?
谢谢,
劳拉
I'm making a specific single.php template. It's using a jQuery slider to slide from one post to the next. In order to show the right post first, I have to use 2 loops - one to call the first single post, and then another loop to call all the other posts in the category.
This I do like this (might be a bit mucky, I'm no PHP guru)
<ul id="tour-items">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</li>
<?php endwhile; endif; ?>
<?php $briefingsposts = new WP_Query(array(
'caller_get_posts' => 1,
'category_name' => Briefings,
'offset' => 1
)); ?>
<?php while ($briefingsposts->have_posts()) : $briefingsposts->the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
However, if the first post is a sticky post, it's repeating in the category loop despite the 'offset' => 1 which I assume is because it's doing it's sticky behaviour and sticking itself to the top.
I've tried using 'caller_get_posts' => 1 in the array but it doesn't seem to make any difference at all. I dont want to exclude sticky posts, just make them behave as normal. Is there a way that might work within my queries?
Thanks,
Laura
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这:
应该可以解决问题。
This:
Should do the trick.