Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php query_posts("cat=3&showposts=5"); ?>

    Maybe try explicitly defining the sort order? It’s supposed to default to DESC, but maybe something’s getting in the way.

    <?php query_posts("cat=3&showposts=5&orderby=date&order=desc"); ?>

    The pagination fails because of a rewrite rule that, in this permalink configuration, is broken. Here’s the rule:

    (.+?)/([^/]+)(/[0-9]+)?/?$ == index.php?category_name=$1&name=$2&page=$3

    I’d love to know what WP function uses those three queryvars; haven’t had much luck grepping for them. Looks like it’s supposed to handle /cat/post/pagenum for posts spanning multiple pages. I don’t have any of those, so I don’t need that rule.

    And here’s the one we want, which appears at the bottom of the list of rules, despite being more specific:

    (.+?)/page/?([0-9]{1,})/?$ == index.php?category_name=$1&paged=$2

    The proper way to handle this problem, if it doesn’t break other parts of WP, would be to reorder the rewrite rules so that the first rule is below the second. But sdemidko’s code solves my problem now, so I’ll leave the research for later.

    I’ve dropped this into a plugin so I don’t have to worry about WP upgrades:

    <?php
    /**
     * workaround_broken_wp_rewrite_rule.php
     *
     * Plugin Name: Workaround Broken WP Rewrite Rule
     * Description: Fixes pagination for /cat-slug/page/2 style URLs
     * Author: _timk
     */
    function workaround_broken_wp_rewrite_rule($query_vars)
    {
      if (@$query_vars["name"] == "page") {
        $qv = array();
        $qv["paged"] = str_replace("/", "", $query_vars["page"]);
        $qv["category_name"] = $query_vars["category_name"];
    
        return $qv;
      }
    
      return $query_vars;
    }
    
    add_filter('request', 'workaround_broken_wp_rewrite_rule');
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)