monthchunks\n";
// get an array of the years in which there are posts
$wpdb->query("SELECT DATE_FORMAT(post_date, '%Y') as post_year
FROM wp_posts
GROUP BY post_year
ORDER BY post_year DESC");
$years = $wpdb->get_col();
// begin unordered list
// each list item will be the year and the months which have blog posts
print "
\n";
foreach($years as $year)
{
// get an array of months for the current year without leading zero
// sort by month with leading zero
$wpdb->query("SELECT DATE_FORMAT(post_date, '%c') as post_month
FROM wp_posts
WHERE DATE_FORMAT(post_date, '%Y') = $year
GROUP BY post_month
ORDER BY DATE_FORMAT(post_date, '%m')");
$months = $wpdb->get_col();
// start the list item displaying the year
// followed by a line break
print "\t- " . $year . "
\n\t";
// loop through each month, creating a link
// followed by a single space
foreach($months as $month)
{
print "" . $month . " ";
}
//end the list item for the given year
print " \n";
}
// end the unordered list
print "
\n\n";
}
?>