A MovableType script. Author: Rob Watkins Author URI: http://www.oneofthosedays.org.uk */ function get_niceArchive($order="DESC", $tableClass="datearc", $tableClassAlt="datearcAlt", $tableClassAlt2="datearcAlt2") { global $wpdb, $tableposts, $month_abbrev; if(!("ASC"==$order)) { $order = "DESC"; } $monthswithposts = $wpdb->get_results("SELECT DISTINCT MONTH(post_date) AS month, MONTHNAME(post_date) as textmonth, YEAR(post_date) AS year FROM $tableposts WHERE post_status = 'publish' ORDER BY year $order, month ASC"); $archive_link = get_settings('siteurl') . '/'; foreach ($monthswithposts as $months) { #turn the list of dates from the database into an array of form "URL monthname year" #"URL" is the link to the archive for that month that is displayed when get_niceArchive() is used. // $monthlyarchive[] = "$archive_link$months->year".zeroise($months->month, 2)." $months->textmonth $months->year"; $monthlyarchive[] = get_month_link($months->year, zeroise($months->month, 2)) . " " . $month_abbrev[__($months->textmonth)] . " $months->year"; } function lightdark($rest, $tableClassAlt, $tableClassAlt2) // function is called upon later on in the script. Returns the correct class for the alternating table. { if($rest%2) { $color = $tableClassAlt; } else { $color = $tableClassAlt2; } return $color; } foreach ($monthlyarchive as $string) { list($link, $month, $year) = split(" ",$string); // monthlyarchive[] is split into three seperate variables $a[$year][] = get_archives_link($link, $month, "custom"); //custom formatted link } reset($a); //resets the internal pointer to the first element in the array if("DESC"==$order) { end($a); } $array_first_key = key($a); //saves the first key of $a (first year in the list) while (count($a[$array_first_key]) % 4 != 0) {//pad out to ensure there are a correct number of cells array_unshift($a[$array_first_key], " "); //... add " " } //now want to sort array based on KEY of A. foreach ($a as $year=>$list_of_strings) { echo "\n"; #the year is used as a headline echo "\n"; #at the beginning of each year a table row is created echo "\n"; $num_cells = 0; foreach ($list_of_strings as $key=>$date_string) { $num_cells++; if(!($key%4 || $key==0)) { // if the key of the array can be divided by 4, a new table row is created. echo "\n\n"; } # a table cell for every shortmonth is created. The color alternates echo "\n"; } $num_cells = 4 - $num_cells % 4; while($num_cells != 0 && $num_cells != 4) { echo "\n"; $num_cells--; } # at the end of each year the table row is closed echo "\n"; echo "
$year
$date_string 
\n"; } } ?>