问题描述

我的分页只是链接到我的首页上的同样的帖子。

我的首页上有 3 个帖子,当我下次浏览/页/2,但只显示相同的 3 个帖子,没有以前的按钮。下一个按钮仍然存在,但仍然转到 page /1

这是完整的查询。

<?php

            query_posts('post_type=post&posts_per_page=3');

            if ( have_posts() ) : while ( have_posts() ) : the_post();

            $category = choose_one_category(get_the_category());

            switch ($category){
                case "Festival News":
                    $left[] = $post;
                    break;
                case "Industry News":
                    $centre[] = $post;
                    break;
                case "Other":
                    $right[] = $post;
                    break;
            }


            endwhile;
            ?>
            <div class="custom-pagination">

            <div ><?php previous_posts_link('&laquo; Previous') ?></div>

            <div ><?php next_posts_link('Next &raquo;') ?></div>
            </div>
            <?php endif;



            ?>

最佳解决方案

建立 Rarst 所说的话,我确信查询字符串将保留’paged’ 查询,即使 WP_Query 将其删除为无关紧要。您可以尝试用以下替换您的查询帖子行:

global $query_string;
parse_str( $query_string, $my_query_array );
$paged = ( isset( $my_query_array['paged'] ) && !empty( $my_query_array['paged'] ) ) ? $my_query_array['paged'] : 1;
query_posts('post_type=post&posts_per_page=3&paged='.$paged);

参考文献

注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。