', '', '
', '', '', true);
This would produce something along the lines of:
(assuming the year is 2004, and you really have posts in the months I'm listing)
2004
January (4)
February (5)
October (2)
May (4)
2003
2002
I feel I should further explain a few of the variables, namely the $open_month and $close_month variables. This is
the main distinction between this version of this "plugin" and the original hack. I've changed the way the markup is
handled, so let me explain. Previously, the entire list was encompassed within one large tag and months were
simply classified differently to create the tabulated effect.
To better handle "strict markup" and better css effects, I've modified this process a bit. Now, each year and it's preceeding
months will be within *one* - tag. The year will be simply printed within the
- , but the months for that year will then
be inserted within a *nested*
tag. Let me illustrate the (in psuedo code) what the above example will now look like:
I didn't feel inclined to write out *all* of the code, but I believe you get the gist of it. The reason for this change is it
allows for easier manipulation of the months. If need an example of what I mean, check out my archives: http://www.blindmuse.com/blog/
The example is actually the on the side bar, not the main area. The main "archive" is a whole other thing entirely.
Enjoy.
*/
function cg_get_archives_by_year ($limit='24', $month_limit='12', $before_year='', $after_year='', $open_month='', $close_month='', $before_month='', $after_month='', $show_post_count = false) {
global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename;
global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb;
// A little formatting for the ul structure;
$before_year = "\n\t" . $before_year;
$after_year = "\n\t" . $after_year . "\n";
$open_month = "\t" . $open_month . "\n";
$close_month = "\t" . $close_month;
$before_month = "\t\t" . $before_month;
$after_month = $after_month;
if ('' != $limit) {
$limit = (int) $limit;
$limit = " LIMIT $limit";
}
// this is what will separate dates on weekly archive links
$archive_week_separator = '–';
// archive link url
$archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal; # monthly archive;
$archive_link_y = $siteurl.'/'.$blogfilename.$querystring_start.'year'.$querystring_equal;
// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
$archive_date_format_over_ride = 0;
// options for daily archive (only if you over-ride the general date format)
$archive_day_date_format = 'Y/m/d';
// options for weekly archive (only if you over-ride the general date format)
$archive_week_start_date_format = 'Y/m/d';
$archive_week_end_date_format = 'Y/m/d';
if (!$archive_date_format_over_ride) {
$archive_day_date_format = $dateformat;
$archive_week_start_date_format = $dateformat;
$archive_week_end_date_format = $dateformat;
}
$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
$thisyear = date('Y');
$arcsql = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit;
$arcresults = $wpdb->get_results($arcsql);
if ($arcresults) {
$arccount = count($arcresults);
$loopcount = 0;
$monthcount = 0;
foreach ($arcresults as $arcresult) {
// Do our loopcount up here
$loopcount++;
$currYear = $arcresult->year;
$y_url = get_year_link($arcresult->year);
$m_url = get_month_link($arcresult->year, $arcresult->month);
if ( $prevYear != $currYear ) {
$y_text = $currYear;
if ($loopcount != 1) {
if (($month_limit > 0 && $thisyear == $prevYear) || ($month_limit == '0' || $month_limit == '')) {
echo $close_month;
}
echo $after_year;
}
echo $before_year . ''. $currYear .'' . "\n";
if (($month_limit > 0 && $thisyear == $currYear) || ($month_limit == '0' || $month_limit == '')) {
echo $open_month;
}
}
// Setup the month text stuff.
if ($show_post_count) {
$m_text = sprintf("%s", $month[zeroise($arcresult->month,2)]);
$m_after = " ($arcresult->posts)$after_month";
} else {
$m_text = sprintf("%s", $month[zeroise($arcresult->month,2)]);
}
// Using the month_limit feature.
if ($monthcount != $month_limit && $thisyear == $currYear) {
echo get_archives_link($m_url, $m_text, "custom" , $before_month, $m_after);
$monthcount++;
} elseif ($month_limit == '' || $month_limit == "0") { // The total limit feature.
echo get_archives_link($m_url, $m_text, "custom" , $before_month, $m_after);
}
if ($loopcount == $arccount) {
if ($month_limit == '') {
echo $close_month;
}
echo $after_year;
}
$prevYear = $currYear;
}
}
}
if (!function_exists('get_year_link')) {
function get_year_link($year) {
global $siteurl, $blogfilename, $querystring_start, $querystring_equal;
if (!$year) $year = date('Y', time()+($time_difference * 3600));
if ('' != get_settings('permalink_structure')) {
$off = strpos(get_settings('permalink_structure'), '%year%');
$offset = $off + 7;
$yearlink = substr(get_settings('permalink_structure'), 0, $offset);
$yearlink = str_replace('%year%', $year, $yearlink);
return get_settings('home').$yearlink;
} else {
return get_settings('home').'/'.get_settings('blogfilename').$querystring_start.'year'.$querystring_equal.$year;
}
}
}
?>