【问题标题】:Infinite next/prev post loop无限下一个/上一个后循环
【发布时间】:2013-08-22 23:51:47
【问题描述】:

使用下面的代码,我尝试为页面(而不是帖子)设置无限的下一个/上一个帖子循环。我的最后一页,前一个按钮链接到一个页面,但下一个按钮链接到我可用的第一个帖子。如何将其更改为仅目标页面?

<div class="port-nav left">
        <?php 
            /**
             *  Infinite next and previous post looping in WordPress
             */
            if( get_adjacent_post(false, '', true) ) { 
        ?>
                <p class="prev"><?php previous_post_link('%link'); ?></p>
        <?php
            } else { 
                $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
                    echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>';
                wp_reset_query();
            };
        ?>
        <?php       
            if( get_adjacent_post(false, '', false) ) { 
        ?>
                <p class="next"><?php next_post_link('%link'); ?>
        <?php
            } else { 
                $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
                    echo '<a href="' . get_permalink() . '">Next Post &rarr;</a>';
                wp_reset_query();
            }; 
        ?>
    </div>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    有点摸不着头脑,因为我目前无法对此进行测试:

    $last = new WP_Query('post_type=page&posts_per_page=1&order=ASC');
    

    【讨论】:

    • 嗯,这似乎将目标从页面更改为帖子。谢谢你。跟进,我怎样才能让这个目标只具有相同类别的帖子?
    • 有什么想法吗?我可以让这个代码只针对同一类别的帖子吗?
    猜你喜欢
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 2013-11-28
    • 2019-04-12
    • 1970-01-01
    相关资源
    最近更新 更多