簡體   English   中英

僅顯示比當前帖子舊的Wordpress帖子

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM