You are here

function archive_month_list in Archive 5

Same name and namespace in other branches
  1. 6 archive.module \archive_month_list()

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.

1 call to archive_month_list()
archive_block in ./archive.module
Implementation of hook_block().

File

./archive.module, line 491

Code

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;
}