Changing post order in WordPress

The site www.oldsoul.com.au needed a different order for displaying the items in the catalogue. The default is date descending and viewing the individual posts the user is given two links, next and previous.

So clicking on the first one takes you to a page with "Previous" which is confusing.

To rectify this the order was changed to Date Descending.

First I tried using some of the many plugins that come up when you search for Post Order. Most of them allow you to have any order you want as long as you are happy to give each post an index number. I just wanted them in title order, and to happen automatically.

One I tried, Q2W3 Post Order, could not be removed. The support site has Russian text so it is not much help.

Quick and Dirty or Clean

To change the order some code editing is required. There are two main ways of doing as explained in an article by Codebabble. First is to edit the file directly and the second better way is to make a child template and do your changes there. This way any template updates won't trash your work. Another explanation is provided in an article by the WordPress site.

Being in a hurry and already having modified code I used the Quick and Dirty method!

Static or Posts

If your site has posts on the home page then modify the index.php in the template folder. For categories, like the Portfolio and Catalogue menu options on www.oldsoul.com.au edit the category.php file.

The Edits

All files are edited the same way. The code goes before the "The Loop" as shown below. To get a handle on how themes work have a read of Yoast's Anatomy of a WordPress Theme.

The & can separate a series of modifications to the query that generated the list of posts to display.

Refer to http://codex.wordpress.org/Function_Reference/query_posts the ones I tried were:

  • &orderby=title&order=ASC
  • &posts_per_page=4

I had problems with both of these. The posts_per_page left posts out of the listing altogether. The orderby displayed the posts in order but on the single post page, Next or Previous did not take you to the relevant post in Title order, it used date order.

There may be a solution but for the moment with just changing the order to ascending the Next and Previous links now makes sense.

Leave a Reply

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram