I just wrote a simple WordPress plugin which creates post archives which are categorized by date. You can find an example of the plugin in action on the new archives page.
- Copy the code linked at the end of this post into a new file
- Save the file as something like
- Upload your new file into your
- Enable the plugin in your WordPress backend
The plugin takes three optional arguments:
void DateArchives ( [ string $headingtag [, string $splitformat [, int $limit ]]] )
- HTML tag which will be used for headings.
- String in strftime format which defines how posts should be categorized. Maybe better to understand if you take a look at my archive page – there I used the default format which results in categories like ‘June 2008’. By changing this string you can categorize your archives by day, month, year, even by hour if you wish so.
- If you got many posts you may want to limit the output to a certain amount of posts. Will output all posts if set to
Note: As all parameters are optional, you can omit them all if you don’t need to tweak the plugin’s output.
You can use the plugin in two ways: either by calling the plugin with WordPress’ Shortcodes in pages or posts or by calling the PHP function directly in your template files.
Shortcode style in pages/posts (please remove spaces after/before parentheses):
[ DateArchives headingtag = "h2" splitformat="%B %Y" limit="0" ]
PHP style in templates:
<?php DateArchives('h2', '%B %Y', 0); ?>
You can grab the latest version of the plugin from the WordPress repository.