A variation on the core Archives widget where it is like a yearly list in addition to the months of the current year.
Recently I wrote a shortcode to reduce the number of archive links displayed in a widget. The shortcode was easier and quicker to develop – I actually wrote the code in a standalone script.
Editing archives markup
The code makes two calls to wp_get_archives(). The first gets a list of yearly archives without <li> and </li> markup, and the second retrieves the monthly archives also without the <li> </li> markup.
For the monthly archives I run it through array_filter() to remove links to months of previous years (it looks for this year before the closing </a> tag). This leaves monthly archive links for the current year.
The year can optionally be removed from the monthly archives link text. This is done with array_map() and a custom callback function.
With two arrays processed I assemble them back into a single array to display.
The current year’s link is optionally added to the top of the line, followed by the monthly archive links (using implode()) and then the rest of the year links.
Converting to a widget
When I had some free time I decided to convert it into a widget as it is easier to deploy and use.
The widget settings allows for a title and then two options – whether to remove the current year from the monthly links and whether to include the current year at the top of the list.
Here is a side-by-side comparison of the core Archives widget vs my Truncated Archives widget. As the site I used this on only has a small number of posts this doesn’t demonstrate the possible reduction in size, but does show the change from monthly links to year/monthly/previous years.