wordpress 中的分页不起作用

Pagination in wordpress is not working

我创建了一个自定义主页,其中包含类别名称。当我单击类别时,我将重定向到另一个名为“page-category.php”的页面,并在 URl 中传递类别 ID。在 page-category.php 页面中,我想捕获 id 并显示自定义的 post 设计以及该特定类别的照片和摘录。但是,如果 post 的数量超过一定数量,我希望在我的页面上进行分页。 None分页功能正常。这是我的代码:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
 $npsPosts = new WP_Query('posts_per_page=5&cat='.$cat_id.'&paged=' . $paged);
            if($npsPosts -> have_posts()):

        next_posts_link( 'Older Entries', $the_query->max_num_pages );
        previous_posts_link( 'Newer Entries' );

          <?php
                while($npsPosts->have_posts()): $npsPosts ->the_post();
                    if ( !in_array( $post->ID, $do_not_duplicate )) {  ?>
                        <div class="horizontal_post_grid_row_col cat-page-box">
                            <div class="horizontal_post_grid_row_col-img">
                                <a href='<?php the_permalink();?>'><?php the_post_thumbnail('medium-thumbnail'); ?></a>
                            </div>
                            <div class="horizontal_post_grid_row_col_content">
                                <h3 style="margin-bottom:5px;"><a href='<?php the_permalink();?>'><?php the_title();?></a></h3>
                                <span class="author_tag">Reading time : <?php echo reading_time(); ?></span> 
                                <div class="excerpt_content"><?php the_excerpt(); ?></div>
                                <div class='keep_reading_text'><a href='<?php the_permalink();?>'>Read more</a></div>
                            </div>
                        </div>
                        <div class="gap-cat">jkn</div>


                    <?php 
              }
                endwhile;

                      next_posts_link( 'Older Entries', $the_query->max_num_pages );
          previous_posts_link( 'Newer Entries' );
    else:
            endif;

我没有在 function.php.When 中添加任何内容 我单击类别选项 我正在发送 URL 就像 "wwww.example.com?id=108" 。我在 page-category.php 中捕获 ID 并显示该类别 ID 的所有 post。 URL 变为 "www.example.com/category/?id=108"。使用分页时,它会变成 "www.example.com/category/page/2/?id=108"。如果不是正确的方法请提出建议。

删除函数 next_posts_link,previous_posts_link 并添加以下代码:

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $npsPosts->max_num_pages
) );