使用WP_QUERY无法进行WordPress分页

时间:2019-12-10 作者:user179536

好的,我知道已经有很多关于这个的帖子了,但我无法找到我的代码有什么问题。因为分页仍不起作用。奇怪的是,相同的代码和模板在我使用它们的另一个站点上运行良好。

<?php
    $type = get_sub_field(\'type\');
    $amount = get_sub_field(\'amount\');
    $previousLabel = $labels[\'previous_label\'];
    $nextLabel = $labels[\'next_label\'];
?>

<div class="block-review block-review-<?php echo($type)?>">
    <div class="content-wrapper">
        <?php 
            if($type == \'list\') {
                // get list of posts
                $pageQuery = (is_home())? \'page\' : \'paged\';
                $paged = (get_query_var($pageQuery)) ? get_query_var($pageQuery) : 1;
                $reviews = new WP_Query(
                    array( 
                        \'post_type\' => \'review\', 
                        \'posts_per_page\' => $amount,
                        \'paged\' => $paged,
                        \'orderby\' => \'date\',
                        \'order\' => \'DESC\',
                        \'meta_key\' => \'meta_data_hide_review\',
                        \'meta_value\' => \'0\'
                    )
                );
                // loop though reviews
                if ($reviews->have_posts()):
                    while($reviews->have_posts()): $reviews->the_post();
                        require(\'element/review-item.php\');
                    endwhile;
                    ?>
                    <div style="display:none"><?php var_dump(get_query_var(\'page\') . get_query_var(\'paged\'))?></div>
                    <div class="review-pagination-wrapper">
                        <div class="review-pagination">
                            <?php 
                                echo paginate_links( array(
                                    \'base\'         => str_replace( 999999999, \'%#%\', esc_url( get_pagenum_link( 999999999 ) ) ),
                                    \'total\'        => $reviews->max_num_pages,
                                    \'current\'      => max( 1, get_query_var( $pageQuery ) ),
                                    \'format\'       => \'?\' . $pageQuery . \'=%#%\',
                                    \'show_all\'     => false,
                                    \'type\'         => \'plain\',
                                    \'end_size\'     => 2,
                                    \'mid_size\'     => 1,
                                    \'prev_next\'    => true,
                                    \'prev_text\'    => sprintf( \'<i></i> %1$s\', __( $previousLabel , \'text-domain\' ) ),
                                    \'next_text\'    => sprintf( \'%1$s <i></i>\', __( $nextLabel , \'text-domain\' ) ),
                                    \'add_args\'     => false,
                                    \'add_fragment\' => \'\',
                                ) );
                            ?>
                        </div>
                    </div>
                    <?php
                else:
                    // no posts
                endif;
                wp_reset_postdata();
            }
        ?>
    </div>
</div>
因此,第一页工作正常,分页显示,但我无法导航到下一页。任何帮助都将不胜感激。

1 个回复
SO网友:user179536

好的,很抱歉发布此问题。有人安装了一个SEO插件,可以将每个连续的页面重定向到第一个页面。

相关推荐

get_post_meta pagination

我有自定义字段,具有多个值的数组$metas = get_post_meta($post->ID, \"$meta_key\", false); foreach ( $metas as $metas ){ echo $metas; } 当然,这将返回一个数组。如何对此分页?例如:www.example.com/post-title/1 将返回meta_value[0]和www.example.com/post-title/2 将