使用 caller_get_posts=1 使 WordPress 粘性帖子正常运行是行不通的

发布于 2024-08-15 18:38:36 字数 982 浏览 4 评论 0原文

我正在制作一个特定的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2024-08-22 18:38:36

这:

$briefingsposts = new WP_Query(array(
 'caller_get_posts' => 1,
 'category_name' => Briefings,
 'offset' => 1,
 'post__not_in'=>get_option('sticky_posts')
 ));

应该可以解决问题。

This:

$briefingsposts = new WP_Query(array(
 'caller_get_posts' => 1,
 'category_name' => Briefings,
 'offset' => 1,
 'post__not_in'=>get_option('sticky_posts')
 ));

Should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文