【问题标题】:Single post next and previous links单个帖子下一个和上一个链接
【发布时间】:2012-10-27 12:28:03
【问题描述】:

(我在别处问过这个问题,但没有得到任何回应)

显示单个帖子时,我有上一个/下一个链接。这可行,但我希望“下一个”链接在显示最后一个帖子时指向第一个帖子,而“上一个”链接在显示第一个帖子时指向最新的帖子。根据文档 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),但链接仍然指向第一个帖子。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    get_boundary_post 接受三个参数:

    • $in_same_cat(默认为 false)
    • $excluded_categories(默认'')
    • $start(默认为真)

    试试

    get_boundary_post(false, '', false);
    

    获取最新帖子。

    【讨论】:

    • 感谢您的回答。我确实尝试过,但是当我在第一篇帖子上时,我的“上一个”链接仍然指向同一个帖子。
    猜你喜欢
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多