In my index.php, I'd like to display only the current month's posts, and if there are no posts in the current month, then keep going back a month until some posts are found.
Here's a first crack at it:
This code goes in index.php just before the Loop starts:
$m = date('m');
$y = date('Y');
query_posts("monthnum=".$m."&"."year=".$y);
while (!have_posts())
{
$m = $m-1;
if ($m == 0)
{
$m = 12;
$y = $y - 1;
}
query_posts("monthnum=".$m."&"."year=".$y);
}
Any comments/suggestions welcome!