Code: Select all
$results = mysql_query("SELECT DISTINCT YEAR(date) AS `year`, DATE_FORMAT(date, '%m') AS `month` FROM blog_posts $where GROUP BY YEAR(date), DATE_FORMAT(date, '%m') ORDER BY date DESC", $connection);
$posts = array();
while ($row = mysql_fetch_assoc($results)) {
if (!isset($posts[$row['year']][$row['month']])) {
$posts[$row['year']][$row['month']] = array();
}
$posts[$row['year']][$row['month']][] = $row;
}
$month_array = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr",
"05" => "may", "06" => "jun", "07" => "jul",
"08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec");
$i=0;
foreach ($posts as $year => $yelement) {
echo '<div id="archcal"><ul>';
echo '<li class="year">'.$year .'';
foreach ($yelement as $month => $melement) {
foreach ($month_array as $mon_key => $month2) {
$class = ($i%2) ? 'class="light"' : 'class="dark"';
if ($month == $mon_key) {
echo '<li '.$class.'><a href='.$month.'>'. $month2 .'</a></li>';
} else {
echo '<li '.$class.'>'.$month2.'</li>';
}
$i++;
}
}
echo '</ul></div>';
}Code: Select all
2008
jan [feb] mar
apr may jun
jul aug sep
oct nov dec
jan feb [mar]
apr may jun
jul aug sep
oct nov dec
jan feb mar
[apr] may jun
jul aug sep
oct nov dec
Code: Select all
2008
jan [feb] [mar]
[apr] may jun
jul aug sep
oct nov dec