美文网首页
wordpress翻页优化

wordpress翻页优化

作者: 一叶一华年 | 来源:发表于2019-05-14 17:57 被阅读0次

    wordpress自带的上下翻页,不是根据一个类别中的页面翻页,而是根据首页列表顺序进行翻页,十分不友好。现更改为一个类别中页面的翻页,如果到最后一个便提示已是最新文章。如果是类别中的第一个页面便提示已是最后文章。(文章是按照最新时间倒序排)
    外观--编辑---single.php添加相关代码

    <?php
        $categories = get_the_category();
        $categoryIDS = array();
        foreach ($categories as $category) {
            array_push($categoryIDS, $category->term_id);
        }
        $categoryIDS = implode(",", $categoryIDS);
    ?>
    <div class="up-down-page">
        <div class="uppage">
            <?php if (get_previous_post($categoryIDS)) { previous_post_link('上一篇: %link','%title',true);} else { echo "已是最后文章";} ?>
        </div>
        <div class="nextpage">
            <?php if (get_next_post($categoryIDS)) { next_post_link('下一篇: %link','%title',true);} else { echo "已是最新文章";} ?>
        </div>
    </div>  
    
    image.png

    相关文章

      网友评论

          本文标题:wordpress翻页优化

          本文链接:https://www.haomeiwen.com/subject/avyeaqtx.html