WordPress Plugin: DateArchives

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.

Installation

  1. Copy the code linked at the end of this post into a new file
  2. Save the file as something like datearchives.php
  3. Upload your new file into your wp-content/plugins folder
  4. Enable the plugin in your WordPress backend

Parameters

The plugin takes three optional arguments:

void DateArchives ( [ string $headingtag   [, string $splitformat  [, int $limit ]]] )
string headingtag
HTML tag which will be used for headings.
(defaults to h2)
string splitformat
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.
(defaults to %B %Y)
int limit
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 0 or null.
(defaults to null)

Note: As all parameters are optional, you can omit them all if you don’t need to tweak the plugin’s output.

Usage

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:

[DateArchives headingtag = "h2" splitformat="%B %Y" limit="0"]

PHP style in templates:

<?php DateArchives('h2', '%B %Y', 0); ?>

Download

You can grab the latest version of the plugin from the wordpress repository.