Post ordering in WordPress

By default, WordPress displays published post in chronological order i.e. most recent at the top. This is fine for blogs, but for news it isn’t what we want.

One way to gain some editorial control over our posts on the home page and/or the category pages, is to use a WordPress plugin called PostMash Filtered.

This plugin works by :

  1. A user interface where you can visually order posts in each category
  2. Modifying the code in the theme files to display the post order

The user interface

The Postmash interface is accessed from the Posts panel:

You then see a list of all your site posts. At the to of this page is a filter where you can choose which category you want to order:

You then just simply drag and drop the posts to achieve your ordering:

Approach

Postmash can be used to easily order posts on your category pages.

Because the postmash plugin orders your category lists, you can’t control the order of your homepage as it is. By default the homepage is ordered by date and posts from different categories can appear there; Postmash won’t affect the orderring because it is purely date based.

This can be overcome by placing all the posts you want on the homepage in a separate special category called, say “Homepage” and setting the homepage template to display that category in the Postmash order.

This can be taken further by treating the homepage as a series of ordered category lists. E.g. you may want featured posts at the top with smaller boxes beneath showing lists of posts from other categories. Remember,  list can consist of just one post!

Example:

Screenshot of a news homepage (click to enlarge)

In the example above, you can see that each block consists of a list of stories. These stories belong to categories that are ordered. The theme then displays the categories in the way that you want.

Editing the Theme code for Category index

This is the tricky part! You need to:

  1. Work out which file to edit
  2. Find the right place to edit

Which file?

This will usually be  the category index.

  1. In the theme editor, locate the file Archive index template (archive.php)
  2. To check if this is the right file, add some random text at the top of the code, save and view a category page – if the text appears you have the right file. (then remove the random text)
  3. Find the beginning of the Loop which starts with .. <?php if(have_posts())…
  4. Before this, paste in:
<?php
$wp_query->set(‘orderby’, ‘menu_order’);
$wp_query->set(‘order’, ‘ASC’);
$wp_query->get_posts();
?>
This just tells WordPress to get the posts ordered according to their ‘menu_order’ position.
Then after that paste in:
<?php query_posts($query_string . ‘&orderby=menu_order&order=ASC’); ?>

Homepage multiple loops

To create separate blocks, each containing an ordered loop, see this article on uSpace:

Custom front page – multiple loops

Leave a Reply