When I need to list all posts in 2011 grouped by month, I'd do something like this in WordPress (pretty straightforward as explained here):
query_posts('monthnum=12&year=2011');
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
Now, how to list all posts and group them by month and year, without knowing how far I should go back? That is, I don't know which year was the oldest post written in. Technically, I could try to do monthnum=12&year=2010
, monthnum=12&year=2009
, and so on; but I feel that there must be a better way.
One solution could be to loop through all years:
This may not be an elegant solution, but use it when there is no better one.