I just made this sort of thing just yesterday.
I am not sure if this is the proper way of doing things but it works for me.
It displays the month and year along with a post count for that month like this:
October 2008 (14)
January 2009 (2)
Februrary 2009 (6)
Code: Select all
<?php
$months=array("January","February","March","April","May","June","July","August","September","October","November","December");
$q="SELECT threads_date FROM forum_threads WHERE threads_spcl = 2 ORDER BY threads_date DESC";
$result=$db->query($q);
while($row=$db->fetchArray($result))
{
$year=substr($row['threads_date'],2,2);
$month=substr($row['threads_date'],5,2);
$month--;
$count[$year][$month]++;
}
?>
<div class="block">
<h2>Blog Archive</h2>
<ul class="links">
<?php
foreach($count as $year => $month)
{
foreach($month as $key => $val)
{
if($key<10) $urlMonth="0".($key+1); else $urlMonth=$key+1;
$urlDate=$year.$urlMonth;
?>
<li><a href="index.php?p=blog&month=<?php echo $urlDate; ?>"><?php echo $months[$key]." 20".$year." (".$val.")"; ?></a></li>
<?php
}
}
?>
</ul>
</div>