Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

6 Ways to Customize WordPress Post Order

[ Graphic: Inverted Triangular Fractal ] Recently, reader Luke Knowles asked how to customize the sort order of his posts in WordPress. Looking into a solution to this question proved quite enlightening. Within moments I was able to discern 4 methods for modifying post order, and then several days later I discovered 2 additional custom sorting techniques. After updating the reply to Luke’s comment, it seemed like some good information that other WordPressers may find useful. So, here are six ways to customize the sort order of posts in WordPress..

The Old Fashioned Way

To customize post order manually, open your theme document and use the following code:

// display posts organized by title in ascending order

<?php $posts = query_posts( $query_string . '&orderby=title&order=asc' ); ?>
<?php if( $posts ) : ?>

	<div class="post">

		<h1>Ordered by Post Title (Ascending)</h1>

		<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

			<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

			<p><?php the_content(); ?></p>

		<?php endforeach; ?>

	</div>
 
<?php endif; ?>

This code is designed to display the specified number of posts in ascending order, according to post title. This code is quite generalized, and may be customized in countless ways. For example, you may modify the order in which the posts are displayed by modifying the orderby and order parameters of query_posts() (in the first line). There are many useful values from which to choose, including category_name and showposts, thereby enabling virtually unlimited post-order customization.

Another useful post-ordering trick involves customizing the post order of, say, categories only, as one might do in an archive or service directory. To limit custom ordering to only categories, replace the first line of the previous loop example with this:

<?php if (is_category()) { $posts = query_posts( $query_string . '&orderby=title&order=asc' ); } ?>

..and then add another endif statement to the end of the loop like this:

<?php endif; ?>
<?php endif; ?>

Of course, it is trivial to restrict post ordering to virtually anything — just replace is_category() in that first line with the is_whatever() statement of your choice:

  • is_home()
  • is_single()
  • is_author()
  • is_search()
  • is_archive()

..etc. For more, check out the WordPress Codex. Okay, that’s enough of that method, let’s move on to some easier custom-sorting methods..

Plugin #1: Custom Query String (Reloaded)

Custom Query String Reloaded is one of the most commonly used WordPress plugins. Custom Query String (CQS) provides a Admin Options panel whereby users may specify any number of custom post queries. CQS enables custom sorting of many different types of queries, including:

  • archive
  • author
  • category
  • date
  • year
  • time
  • search
  • home

..as well as individual categories, feeds, and several others. For each of these query types, users may customize the sort order by date, category, title, or author — in either ascending or descending order. This is a remarkable, highly flexible plugin that has served me well on a number of WordPress-powered sites.

Plugin #2: Smart Sort Plugin for WordPress

Smart Sort actually enables your visitors to select the order in which posts are displayed. Post-order options are presented to visitors as a “sort bar”, which includes a list of customizable ordering options. The sort bar may be placed anywhere within the document template, while displayed sorting options are controlled via the plugin’s WP Admin panel. Although I have not yet tried this plugin personally, it definitely sounds promising.

Plugin #3: aStickyPostOrderER

Although the current version (0.2.2.7) only works for WP 2.3 or better, the AStickyPostOrderER plugin enables users to customize post order according to category, tag, or the entire set of posts. Via the plugin’s comprehensive Options panel, users may customize the sort-order of any or all posts within a specific category or tag. Additionally, users may specify a generalized order in which posts from any category or tag are displayed. For example, you could customize your post order so that:

And this is just off the top of my head. Clearly, aStickyPostOrderER is an ideal plugin for highly customized tag, category, and overall post ordering. A useful plugin for helping people transform WordPress into a full-blown CMS.

Plugin #4: WP-Snap Plugin

As described at the plugin’s homepage, “WP-SNAP! (WordPress System for Navigating Alphabetized Posts) creates an alphabetical listing of post titles on a Category or Page template file.” With WP-SNAP!, users may customize the sort order of posts in category or page views by returning the post query in alphabetic order. Displaying posts in alphabetic post order is perfect for sites featuring directories, glossaries, indices, and other types of reference content. WP-SNAP! provides three unique navigational settings, works great with permalinks, and provides several other useful features.

If you are running WordPress 2.1 or better and are looking for an easy way to alphabetize your post order and provide easy “A-to-Z” navigation, WP-SNAP! may be the perfect solution.

Plugin #5: Sort Category Posts by Title

Although I have yet to try it, this plugin looks like a quick and easy way of sorting category posts in ascending alphabetical order according to post title. According to the plugin’s homepage, WordPress Sort Category Posts By Title was designed for WordPress 2.0.2 and only customizes the sort order of posts displayed in category view — it will not effect the ordering of posts seen elsewhere (e.g., the home page) in the site. The code for this plugin seems clean, simple, and just begging for further exploration and adaptation ;)

Wrap it up..

Regardless of your specific custom-post-ordering needs, one of these methods is sure to fill the suit. While this list is by no means comprehensive, it definitely should get you going in the right direction. Please let me know if you can think of any methods/plugins that are not on the list. — Peace!

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
Wizard’s SQL for WordPress: Over 300+ recipes! Check the Demo »

37 responses to “6 Ways to Customize WordPress Post Order”

  1. Jeff Starr 2009/03/15 4:37 pm

    My pleasure, Tuan Anh — glad the article is useful for you :)

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
SAC Pro: Unlimited chats.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.