function _archive_node_types in Archive 7
Same name and namespace in other branches
- 5 archive.inc \_archive_node_types()
- 6 archive.pages.inc \_archive_node_types()
- 7.2 archive.pages.inc \_archive_node_types()
Returns the different node types that have nodes.
Parameters
$date: A date object obtained from _archive_date().
Return value
An array of node-types to number of posts of that type.
2 calls to _archive_node_types()
- theme_archive_navigation in ./
archive.pages.inc - Theme the archive navigation with years, months and dates by default.
- theme_archive_navigation_node_types in ./
archive.pages.inc - Theme the list of node types for the archives.
File
- ./
archive.pages.inc, line 166 - Pages for the archive module.
Code
function _archive_node_types($date) {
$types = variable_get('archive_type_filters', array());
// Confine the display interval to only one day
if ($date->day) {
$start = mktime(0, 0, 0, $date->month, $date->day, $date->year);
$end = mktime(0, 0, 0, $date->month, $date->day + 1, $date->year);
}
elseif ($date->month) {
$start = mktime(0, 0, 0, $date->month, 1, $date->year);
$end = mktime(0, 0, 0, $date->month + 1, 1, $date->year);
}
elseif ($date->year) {
$start = mktime(0, 0, 0, 1, 1, $date->year);
$end = mktime(0, 0, 0, 1, 1, $date->year + 1);
}
else {
$start = 0;
$end = 0;
}
// Setup the query.
$query = db_select('node', 'n');
$query
->innerJoin('node_type', 't', 't.type = n.type');
$query
->fields('t', array(
'type',
'name',
));
$query
->addExpression('COUNT(n.nid)', 'node_count');
$query
->condition('n.status', 1);
$query
->condition('t.type', $types, 'IN');
$query
->groupBy('n.type');
$query
->orderBy('n.created', 'ASC');
$query
->addTag('node_acces');
if ($start && $end) {
$query
->condition('n.created', array(
$start - $date->tz,
$end - $date->tz,
), 'BETWEEN');
}
$result = $query
->execute();
$n_types = array();
foreach ($result as $row) {
$n_types[$row->type] = array(
'count' => $row->node_count,
'name' => $row->name,
);
}
ksort($n_types);
return $n_types;
}