网站特定分类归档页面Pagination Bug问题排查咨询
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.phpor any custom plugins for code that modifiesposts_per_pagespecifically for the service category. Look for something like this:
If you seeadd_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! } }posts_per_pageset 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.phplike:
If you're using a custom query, you need to pass its pagination data to$custom_query = new WP_Query(array('post_type' => 'post', 'category_name' => 'service'));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.phpor 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.
4. Refresh Permalink Rules
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

