Quick Tip #2 – Changing the post order on WordPress’s category/archive pages

Posted on

I've had this problem (changing the order on those darn categories pages) from day one since working with WordPress and it really bugged me when I'd had to resort to plugins to solve the problem. Basically, when you select different categories in WordPress the post order and category is set in a query which you can't see. It might look something like this -

When I've wanted to change the order to ascending I've tried to add the following into the archive.php file above the loop.

This then messed up the categories selection and the post order on the page. Then I found $query_string which you can add to the start of the query_posts() function which holds the original query generated by WordPress!

You can then carry on with your custom query, but don't forget the & at the start of your query as you are joining it on to WordPress's post order query.

Here's an example of a slimmed down loop you can use.


Add your comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>