I’m currently using wp_get_archives('type=monthly')
to display archive links in my sidebar. This is the output:
<ul>
<li><a href='http://example.com/2011/08/'>August 2011</a></li>
<li><a href='http://recently.se/2011/07/'>July 2011</a></li>
<li><a href='http://recently.se/2010/12/'>December 2010</a></li>
</ul>
Is it possible to group the months by year instead? Something like this:
<ul>
<h2>2011</h2>
<li><a href='http://example.com/2011/08/'>August 2011</a></li>
<li><a href='http://recently.se/2011/07/'>July 2011</a></li>
<h2>2010</h2>
<li><a href='http://recently.se/2010/12/'>December 2010</a></li>
</ul>
This is how I implemented it, although I’m sure there’s a better way. I added these functions to my theme’s functions.php file:
You would call this function instead of wp_get_archives() in your theme like so:
The function names can be whatever you want, although good practice is to prefix them with your theme’s name (i.e. twentyeleven_)
I referenced wp_get_archives() and get_archives_link() in wp-includes/general-template.php.