WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a series of posts that fall within a category of "calendar". I want to produce a list of them in date order. The post titles can begin with the date but I can't see a way of sorting by it. Being British, I'd prefer something in the format dd/mm/yy and I guess North American users would prefer mm/dd/yy. At the moment, the only way I can achieve this is using the format yy/mm/dd which few people can understand.

Any thoughts on how to achieve this?

Many thanks, Graham.

share|improve this question
To be clear: sorting by post creation time will not work here? ([catlist orderby=date]) This is a calendar of future events? – Jan Fabry Sep 10 '11 at 11:41

This is a bit hacky, but you could create your own template and then reformat the date.

start by creating a folder list-category-posts in your theme directory. copy the default.php template there from the plugin's templates folder, and rename it custom.php, or whatever you'd like.

within that custom.php file, find the line:

//Show the title and link to the post:
$lcp_display_output .= $this->get_post_title($single);

and replace it with:

//Show the title and link to the post:

$temp_title = $this->get_post_title($single);

preg_match("/\<a.*href=\"(.*?)\".*?\>(.*)\<\/a\>+/", $temp_title, $matches);

$temp_date = substr($matches[2], 0, 10);
$new_title = substr($matches[2], 11);

$timestamp = strtotime($temp_date);
$new_date = date("j F, Y", $timestamp);

$lcp_display_output .= '<a href="' . $matches[1] . '">' . $new_title . ' - ' . $new_date . '</a>';

For this to work, your posts should be titled:

YYYY/MM/DD Event title

If the day or month is a single digit, it MUST have a leading zero.

The reformatted result will be:

Event title - 9 September, 2011

The part that's reformatting the date is here:

$new_date = date("j F, Y", $timestamp);

If you want to change this, have a look at PHP's Date function for your options.

The last line is reassembling the various bits back together, you can change the order of title - date as well as the hyphen separating them if you'd like.

The shortcode to load your custom.php template and sort by title is:

[catlist name=calendar template=custom orderby=title]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.