I was presented with this challenge while putting together a magazine-type site, where the home page was to display articles from the current issue–meaning the current month and year. Checking the forums, I found some solutions, and although the topics have been closed, I have found that they are incomplete. Some call the current month, i.e. “March”, but don’t not discern the current year, showing posts from March 2013, March 2012, etc. And some simply don’t work at all, sorry to say.
Here’s what I came up with, and have proven to work…
<?php $current_year = date('Y', current_time('timestamp')); $current_month = date('m', current_time('timestamp')); query_posts("year=$current_year&monthnum=$current_month"); if(have_posts()) : while(have_posts()) : the_post(); ?> // YOUR POST MARKUP <?php endwhile; endif; wp_reset_query(); ?>
Of course, there is room to pass way more arguments within
query_posts(), but that’s the easy part.