Index: archive.module =================================================================== --- archive.module (revision 768) +++ archive.module (working copy) @@ -184,21 +184,78 @@ return theme('table', $day_headers, $rows, array(), $month_title); } +/** + * Return a list of links suitable to be passed to theme_links() that represent + * months containing posts. Limit the number of past months to 6 and then have a + * link to the general archives page. + */ +function archive_month_list() { + $node_query = db_query(db_rewrite_sql('SELECT n.created FROM {node} n WHERE n.status = 1 AND DATE(FROM_UNIXTIME(n.created)) BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE() ORDER BY n.created DESC')); + $months = array(); + $total_months = 0; + $max_months = variable_get('archive_block_months', 6); + while ($node = db_fetch_object($node_query)) { + list($month_name, $year, $month) = explode(' ', format_date($node->created, 'custom', 'F Y n')); + if (isset($months[$year][$month])) { + $months[$year][$month]['count']++; + } + else if ($total_months++ < $max_months) { // Limit total months to 10 + $months[$year][$month] = array( + 'count' => 1, + 'month_name' => $month_name + ); + } + } + + return $months; +} /** + * Returns a list of archive months. + */ +function theme_archive_month_list($list_items) { + // Sort by year then by month + krsort($list_items); + foreach ($list_items as $year => $v) { + krsort($list_items[$year]); + } + $links = array(); + foreach ($list_items as $year => $months) { + foreach ($months as $month => $data) { + $links[] = l(t($data['month_name'] . ' ' . $year), 'archive/all/' . $year . '/' . $month, array('title' => format_plural($data['count'], '1 post', '@count posts'))); + } + } + if (count($links) == variable_get('archive_block_months', 6)) { + $links[] = '