简体   繁体   English

仅显示比当前帖子旧的Wordpress帖子

[英]Only display Wordpress posts that are older than current post

I've done my hour+ research to find any answer but cannot find a solution. 我已经完成了我的小时+研究以找到任何答案,但无法找到解决方案。

Anyways... I have a wordpress posts page and on individual posts I have a query to display the latest 4 posts at the bottom of each post page. 无论如何...我有一个wordpress帖子页面和个别帖子我有一个查询显示每个帖子页面底部的最新4个帖​​子。

What I'd like to do is only show 4 posts that are older than the current post page a visitor is on. 我想要做的只是显示4个比访问者所在的当前帖子页面更早的帖子。 Currently it shows the latest 4 entries no matter which post you're viewing. 目前,无论您正在查看哪个帖子,它都会显示最新的4个条目。

Thank you. 谢谢。

<ul>
<?php $the_query = new WP_Query( array (
'post__not_in' => array( $post->ID ),
'posts_per_page' => 4, 
'ignore_sticky_posts' => 1
) ); ?>

<div class="row">
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li class="col-xs-12 col-md-3">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); 
?>">

<?php the_post_thumbnail( 'post-thumbnail', ['class' => 'img-responsive 
responsive--full'] ); ?>
</a>
<?php endif; ?>
<a href="<?php the_permalink() ?>"><p><?php the_title(); ?></p></a>
</li>

<?php 
endwhile;
wp_reset_postdata();
?>
</div>
</ul>

You can use get_previous_post() to get the previous post. 您可以使用get_previous_post()来获取上一篇文章。 use this in a loop (assuming $post variable is updated for every post) to get previous 4 posts. 在循环中使用它(假设为每个帖子更新$ post变量)以获得前4个帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM