(我在其他地方也问过这个问题,但没有得到任何回应)
当显示一篇文章时,我有上一篇/下一篇链接。这是可行的,但我希望“下一篇”链接指向最后一篇文章时的第一篇文章,而“上一篇”链接在第一篇文章显示时指向最新的文章。根据文档,get_boundary_post()应该能够获得第一个或最后一个帖子。下面是我的single.php中的内容:
<?php
$prev_post = get_adjacent_post( true, '', true );
$next_post = get_adjacent_post( true, '', false );
if($next_post == '')
{
$next_post = get_boundary_post();
}
if($prev_post == '')
{
$prev_post = get_boundary_post(); //???
}
$prev_post_id = $prev_post->ID;
$next_post_id = $next_post->ID;
<a href="<?php echo get_permalink($prev_post); ?>">previous</a>
<a href="<?php echo get_permalink($next_post); ?>">next</a>
?>
获取最后一篇文章的第一篇文章链接有效,但获取第一篇文章的最新文章链接不起作用。我不确定如何调用get_boundary_post()来获取最新文章,我已经尝试将其'start‘参数设置为false (默认值为true),但链接仍然指向第一篇文章。
发布于 2012-10-27 13:15:30
get_boundary_post有三个参数:
试一试
get_boundary_post(false, '', false);
来获取最新的帖子。
https://stackoverflow.com/questions/13100177
复制