Display a list of node types with comment count, last post w/links
Last modified: May 17, 2008 - 22:33
Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common problems.
Specifically, the snippet
- bypasses node access restrictions; you can either pass the query through db_rewrite_sql or use node_load on selected nids.
This may involve some serious query rewriting though
This is a very useful code (at least for me). It shows a list of node types, node posts count, last post date and a link to the last node published. May also work for 5.x and 6.x.
<?php
$header = array ('Content', 'Count', 'Last post date','Last post');
$rows = array();
$q = "SELECT n.type as tipo,count(n.type) as cant,max(DATE_FORMAT(FROM_UNIXTIME(n.changed), '%Y-%m-%d')) as lastpost
FROM
{node} n
group by n.type";
$result = db_query ($q);
while ( $row = db_fetch_object ( $result ) )
{
$q = "SELECT max(n.nid) as max FROM {node} n where n.type='$row->tipo'";
$result2 = db_query ($q);
$r = db_fetch_object ( $result2 );
$q = "SELECT n.nid as nid,n.title as title FROM {node} n where n.nid=$r->max";
$result2 = db_query ($q);
$r = db_fetch_object ( $result2 );
$link = l($r->title, "node/".$r->nid);
$rows[] = array ( 'data' => array ( t($row->tipo), $row->cant,$row->lastpost, $link )) ;
}
if (!$rows) {
$rows[] = array(array('data' => t('No log data available.'), 'colspan' => 2));
}
print theme('table', $header, $rows);
?>