monthchunks plugin for Wordpress
The latest version is 2.1, updated January 5, 2006
Inspiration
From a comment on a previous post:
I love your blog design a lot. I especially *LOVE* your MONTHCHUNKS archives. (It’s tiny, clean and stylish!) Is it possible to post a tutorial on how to achive that sort of layout? I really really wish to add the same MONTHCHUNKS to my blog :D –golfy
Sure golfy, no problem. Back when I used Blogger to generate Justinsomnia, I had to write some JavaScript to transform Blogger’s standard archive link list into something a little more compact. But with Wordpress, I was able to write a little code to get the job done in PHP on the server.
Thanks to Jackson for initially suggesting I turn my monthchunks function into a fully-fledged Wordpress plugin.
Output
The monthchunks plugin outputs the links to your archives as list items by year, with a link to each month by number:
When you’re viewing a monthly archive page, the number for that month will be bold and not linked (new in v2.0).
Note: Like the default behavior of wp_get_archives(), monthchunks() only outputs list items <li>...</li> for each year (new in v2.0). When you call the function, make sure that it’s wrapped in <ul> or <ol> tags, e.g.
<ul> <?php monthchunks(); ?> </ul>
Instructions
- Download and unzip monthchunks-2.1.zip (v2.1)
- Upload the file monthchunks.php to your plugins directory:
/path/to/wordpress/wp-content/plugins - Activate the plugin (don’t forget!)
- Edit the theme template file sidebar.php in your theme’s directory:
/path/to/wordpress/wp-content/themes/name-of-theme - In the default Wordpress theme, you can replace the function
wp_get_archives('type=monthly');withmonthchunks();by changing this snippet of code:<li><h2>Archives</h2> <ul> <?php wp_get_archives('type=monthly'); ?> </ul> </li>to this:
<li><h2>Archives</h2> <ul> <?php monthchunks(); ?> </ul> </li>
Options
The monthchunks function can take two optional parameters in between the parentheses.
<?php monthchunks(year_order, month_format); ?>
- year_order is a string (
"ascending"or"descending") that determines whether the years are displayed in ascending (e.g. 2001, 2002, 2003…) or descending (e.g. 2003, 2002, 2001…) order. The default is ascending. - month_format is a string (
"numeric"or"alpha") that determines whether the month links are printed out as numbers (e.g. 1 2 3 4…) or letters (J F M A…). The default is numeric.
If you wanted to sort the years in descending order with letters for each month, you’d do this:
<li><h2>Archives</h2>
<ul>
<?php monthchunks("descending", "alpha"); ?>
</ul>
</li>
As always, let me know if you have any questions or problems. Enjoy!
See monthchunks for blogger for a way to create similar output using JavaScript.
Update: Monthchunks was included in the Japanese book, WordPress 標準ガイドブック (Standard Guidebook), and on its accompanying CD. Check it out!


This would work well as a plugin, so all you have to is drop it into
update: I removed the link to jackson’s earlier version of the code. Use the link in the post above. –justin