You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

网站特定分类归档页面Pagination Bug问题排查咨询

Troubleshooting Pagination Failure on Single Category Page

Hey there! Let's figure out why only your /category/service/ page has broken pagination while other category archives work fine. Since the issue is isolated to this one category, we can target our checks to a few key areas:

1. Verify Post Count Settings for the Category

First, double-check if this category has a custom post-per-page override that's throwing off pagination:

  • Go to Settings → Reading in your WordPress admin and confirm the "Blog pages show at most" value (e.g., 10 posts).
  • Check your theme's functions.php or any custom plugins for code that modifies posts_per_page specifically for the service category. Look for something like this:
    add_action('pre_get_posts', 'custom_service_category_posts_per_page');
    function custom_service_category_posts_per_page($query) {
        if ($query->is_category('service') && $query->is_main_query()) {
            $query->set('posts_per_page', -1); // This disables pagination entirely!
        }
    }
    
    If you see posts_per_page set to -1, that's the culprit—change it to a positive number matching your global setting.

2. Check for Modified Main Query in category.php

Your pagination code relies on WordPress's main query ($wp_query) to calculate page counts. If your category.php template uses a custom WP_Query without proper setup, pagination will break:

  • Look for custom query code in category.php like:
    $custom_query = new WP_Query(array('post_type' => 'post', 'category_name' => 'service'));
    
    If you're using a custom query, you need to pass its pagination data to paginate_links() explicitly, or stick with the main query. Here's a fixed example:
    // Set up paged parameter for custom query
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $custom_query = new WP_Query(array(
        'post_type' => 'post',
        'category_name' => 'service',
        'paged' => $paged
    ));
    
    // Render pagination with custom query data
    if (paginate_links(array('total' => $custom_query->max_num_pages))) { ?>
        <div class="paginate-links archive-paginate-links">
            <?php echo paginate_links(array(
                'total' => $custom_query->max_num_pages,
                'current' => $paged
            )); ?>
        </div>
    <?php }
    wp_reset_postdata(); // Always reset after custom query!
    

3. Rule Out Theme/Plugin Conflicts

Isolate the issue with quick tests:

  • Switch to a default WordPress theme (like Twenty Twenty-Four) and check if pagination works on the service category. If it does, the problem is in your current theme's category.php or related functions.
  • Disable all plugins one by one, reloading the service category page after each disable. If pagination starts working, the last plugin you disabled is the conflict source—check its settings or reach out to the developer for fixes.

Sometimes broken rewrite rules can mess up pagination:

  • Go to Settings → Permalinks in your admin.
  • Don't change any settings—just click the Save Changes button. This refreshes WordPress's rewrite rules, which often fixes pagination glitches caused by permalink structure issues.

5. Ensure Pagination Code is in the Right Context

Make sure your pagination code is placed after the main loop in category.php, and that it uses the global $wp_query correctly. If your loop uses while (have_posts()) : the_post();, try explicitly passing query parameters to paginate_links() to avoid ambiguity:

global $wp_query;
if (paginate_links()) { ?>
    <div class="paginate-links archive-paginate-links">
        <?php echo paginate_links(array(
            'total' => $wp_query->max_num_pages,
            'current' => max(1, get_query_var('paged')),
        )); ?>
    </div>
<?php }

Start with these steps—odds are one of them will fix the isolated pagination issue on your service category page!

内容的提问来源于stack exchange,提问作者user1739542

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:54:44