For a piece of software with its roots firmly in the world of online writing, WordPress users are often surprised by the absence of what seem like obvious bits of blogging functionality. A classic case in point is the lack of easy default ways to re-order your blog posts.

In this piece, we’ll step through two options available to you for solving this problem, pointing you to relevant links and plugins along the way. However, before we get into all of that, let’s start with a bit of background on how post sorting actually works in WordPress.

How WordPress Handles Default Post Order

The story of how WordPress handles default post order is not a particularly long and complicated one – the simple summary is that it does it by post date. Let’s say, for our own mysterious purposes, we’ve decided to turn A Tale of Two Cities by Charles Dickens into a series of blog posts. As you can see below, we’ve got the option of sorting by both title and post date in the back end:

Basic sort options in the admin.

Some basic post sorting options are available in the WordPress admin.

Unfortunately, even this basic functionality is denied to us on the front end. Here, posts are simply listed chronologically by default, with no options to filter or adjust them:

Posts are listed chronologically on the front end.

Posts are fixed in chronological order on the front end.

While this may be a thrilling nod to Dickens’ trailblazing adoption of serialization back in the day, it’s actually a bit of a UX disaster. If we’re trying to encourage people to read a linear narrative, it’s a bit much to ask them to start at the bottom and read up.

Poking around inside default WordPress options, we’re basically presented with two choices at this stage:

  1. Use sticky post functionality.
  2. Start retrospectively changing post dates to force the order we want.

The first option is woefully inadequate in terms of the control needed. The second quickly becomes hard to manage when we’re dealing with large pools of content. It’s also potentially a complete non-starter for sites where the date is a critical component of individual pieces – news sites, for example.

So, long story short – the baked in options to re-order your blog posts are lacking. However, as with most things WordPress, a solution is at hand – two of them in fact.

How to Re-Order Your Blog Posts (with 2 Methods)

One of the great things about WordPress is its flexibility. With that in mind, we’ve offered two solutions to re-order your blog posts – both manual and plugin options. Let’s step through them in turn.

Option 1: Roll Your Own Ordering Solution

One of the many plus points of using WordPress as a blogging or business solution is that if things aren’t quite to your liking, you’ve always got the option of stepping in and changing them around yourself.

This doesn’t have to be a dauntingly technical undertaking either. Before we get cracking, back up your site and bone up on your File Transfer Protocol (FTP) knowledge if necessary. Once you’re ready, come back!

Firstly, let’s have a quick look at a proof of concept change. Once you’ve logged into your FTP client, navigate to the functions.php file in your /wp-content/themes/your-theme folder. Here, we’ve added a simple function just to check if control over post order is possible:


function change_query_order( $query ) {
if ( $query-is_home() && $query-is_main_query() ) {
$query-set( 'orderby', 'title' );
$query-set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'change_query_order' );

Once you’ve saved the file and checked our website, we should be looking at our posts sorted in ascending alphabetical order once we refresh the page:

Post listed in ascending alphabetical order.

A simple code tweak lists posts in ascending order of title.

However, kludging together quick and dirty functions at the end of functions.php is a little old-school. Really, this type of business should be taken care of in a custom plugin.

With that in mind, this tutorial is an excellent breakdown of exactly how to go about achieving it. It also includes working code nicely packaged up at GitHub. This series is also well worth a look if you’re thinking of rolling up your sleeves and diving into the code yourself.

Option 2: Use the Post Types Order Plugin

This being WordPress, there are of course also existing plugins that tackle this problem of post order. The one we’ll look at is the Post Types Order plugin:

Post Types Order plugin.

Our recommended Post Types Order plugin.

While it offers the functionality we require, in addition it’s regularly updated, boasts an impressive 400,000+ active installs, and has rock-solid ratings from a host of satisfied users. There’s also a more full-featured premium version of the plugin available – in the shape of the Advanced Post Types Order plugin – for just $35.

Installation is a snap, but you’ll be prompted to pop into the plugin’s settings page after activating:

Prompt to visit plugin's settings page.

The basic options you see after clicking through are pretty straightforward, with several useful links offering code samples for places where you may need to step in:

Post Types Order plugin settings page.

Although the options may look overwhelming, using the plugin is incredibly simple and works exactly as you’d expect. Once activated, navigate to Posts > All Posts, and you’re free to pick up individual items and rearrange them in the order you want. Below, we’re busy getting that Dickens order the way we want it:

Drag and drop to order posts.

Dragging and dropping posts into order is straightforward.

Changes will then automatically be picked up on the front end. For more of a feel for just how easy this is once the plugin is installed, check out the demo video below. It’s from an older version of the plugin, but it gets the basic point across nicely:

Conclusion

Because WordPress is so flexible, post sorting feels like the kind of functionality that should arrive out of the box, with substantially better default options to hand. Sadly, that’s not the case. However, we do have manual and third-party options at our disposal for getting things arranged how we want.

In this post, we’ve shown you two methods to re-order your blog posts. Let’s recap:

  1. Create your own custom code: If you’re comfortable with ‘rolling your own’, just a few lines of code is probably all that’s required to help arrange things to your pleasing.
  2. Use an existing plugin: In our tests, the Post Types Order plugin stood out for its simplicity and ease of use. Having the option of upgrading to a commercial version for more in-depth sorting options is also reassuring.

Do you have any questions on how to re-order your blog posts? Get in touch via the comments section below, and make sure you subscribe to the conversation!

Article thumbnail image: HeydarovTabriz / shutterstock.com.

The post How to Re-Order Your Blog Posts (with 2 Methods) appeared first on Elegant Themes Blog.

Powered by WPeMatico

Canadian Web Hosting [Ad]

Canadian Web Hosting [Ad]