Numero di nodi per ogni tipo di nodo
Questo snippet ritorna una tabella con ogni tipo di nodo e il rispettivo numero di nodi pubblicati negli ultimi 3 anni.
<?php
#in template.php:
function custom_count_pull(){
$sql = "SELECT type, COUNT(nid) AS number, FROM_UNIXTIME(created, '%Y') AS createdate FROM {node} GROUP BY type, createdate ORDER BY createdate DESC";
$result = db_query($sql);
$article_count = array();
while ($data = db_fetch_object($result)){
if (isset($article_count[$data->type])) {
$article_count[$data->type][$data->createdate] = $data->number;
} else {
$article_count[$data->type] = array($data->createdate => $data->number);
}
}
$today = date("Y");
$years = array($today-2,$today-1,$today);
$output .= "<table><tr><th>Type</th><th>{$years[0]}</th><th>{$years[1]}</th><th>{$years[2]}</th></tr>";
foreach ($article_count as $type => $value) {
$real_type_name = node_get_types('name', $type);
$output .= "<tr> <td>$real_type_name</td>";
foreach ($years as $year) {
if ($value[$year]):
$output .= "<td>{$value[$year]}</td>";
else:
$output .= "<td>0</td>";
endif;
}
$output .= "</tr>";
}
$output .= "</table>";
return $output;
}
?>
