[英]Only display Wordpress posts that are older than current post
我已经完成了我的小时+研究以找到任何答案,但无法找到解决方案。
无论如何...我有一个wordpress帖子页面和个别帖子我有一个查询显示每个帖子页面底部的最新4个帖子。
我想要做的只是显示4个比访问者所在的当前帖子页面更早的帖子。 目前,无论您正在查看哪个帖子,它都会显示最新的4个条目。
谢谢。
<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>
您可以使用get_previous_post()来获取上一篇文章。 在循环中使用它(假设为每个帖子更新$ post变量)以获得前4个帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.