On my homepage I am showing only the current month's posts. I'd like to include a link to the previous month's posts at the bottom of the page.
get_month_link (http://codex.wordpress.org/Function_Reference/get_month_link). I can use this function like so to get the month number, minus 1 = previous month:
$archive_year = get_the_time('Y'); $archive_month = get_the_time('m'); $previous_month = $archive_month - 1 <a href="<?php echo get_month_link( $archive_year, $previous_month ); ?>">Last month's posts</a>
This will output a link like "/?m=201308" if the month is September.
In most cases this will work, but when I get to January, the
$previous_month var will be "01 - 1", and won't give me "12" for December's posts.
Any ideas how to make this a little more fail-safe for situations like December?