How to Sort WordPress Posts by Title
Posted on March 5, 2008
Filed Under WordPress Customization, WordPress Coding |
By default WordPress posts are ordered by posting dates, the last posted articles come first. That makes sense for most WP sites because blogs after all are cronicle journals. But WP can be used for many types of websites rather than blog. In many cases you would prefer to display articles by alphabetic order.
This feature is easy to customize. The display of posts is controlled by WP function “query_posts” where you can specify a parameter “orderby” to get your posts sorted in many ways. To order posts by title, just set orderby to “title”. The code looks likes this:
<?php $posts = query_posts( $query_string . ‘&orderby=title&order=asc’ ); ?>
If you don’t want to mess up with code, there are several plugins to help. The following article from Perishable Press outlined a few good ones - Custom Query String, Smart Sort, and aStickyPostOrderER.
6 Ways to Customize WordPress Post Order • Perishable Press
I don’t use any of them because I usually like to fix the code. But plugins can be really handy too.
Comments
Leave a Reply