我读出了 wordpress codex 以显示上一篇文章和下一篇文章,它工作正常。但是,当我从当前帖子查看它时,如何显示前 5 个带有超链接的帖子标题和下一个带有超链接的 5 个帖子标题。例如:
帖子 1、帖子 2、帖子 3、帖子 4、帖子 5
当我查看 ** Post 3** 时,它会将上一篇文章显示为Post 1 和 Post 2 ,而 Next post 显示Post 4 和 Post 5
我怎样才能做到这一点?
您可以通过以下方式获得
<?php global $post;
$current_post = $post; // remember the current post
for($i = 1; $i <= 5; $i++):
$post = get_previous_post(); // this uses $post->ID
setup_postdata($post);
// do your stuff here
the_title();
the_content();
endfor;
$post = $current_post;
?>
也适用于 newt 5 post 使用get_next_post()
,而不是get_previous_post()