[英]Wordpress - Exclude most recent post from loop
I'm making a blog page where the most recent post is featured and displayed differently from the other posts. 我正在制作一个博客页面,其中最新文章的特色和显示方式与其他文章不同。 I'm doing that with WP_Query->query('showposts=1');
我正在使用WP_Query-> query('showposts = 1'); and it's working fine.
而且工作正常。 I also have wp_reset_postdata();
我也有wp_reset_postdata(); after the end of the while loop.
在while循环结束之后。
Next, I have another loop where I want to show 9 posts without the most recent one. 接下来,我有另一个循环,我想显示9条帖子,而没有最新的帖子。 I'm using the following code found on wpbeginner.com:
我正在使用wpbeginner.com上的以下代码:
query_posts('posts_per_page=9&offset=1');
if(have_posts()) :
...
It seemed to be working fine until I checked the older posts page - it displays the same posts! 在我查看较旧的帖子页面之前,它似乎工作正常,它显示相同的帖子! I tried to add sorting by date, wp_reset_postdata();
我试图添加按日期排序,wp_reset_postdata(); and some other solutions, but nothing worked.
和其他一些解决方案,但没有任何效果。
Am I missing something, or is this method flawed? 我是否缺少某些东西,或者这种方法有缺陷?
Its happening as because you have changed the query through query_posts functions. 发生这种情况的原因是您已通过query_posts函数更改了查询。 Please use WP_QUERY instead of it.
请使用WP_QUERY代替它。
$args = array(
'post_type'=> 'post',
'offset'=>1,
);
$query=new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post();
echo get_the_ID();
endhwhile; endif;
hope it will work for you. 希望它对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.