Drupal: Display List of The Newest Node Titles
In this article, I would tell you how to show a list of the newest nodes titles. The list will be sorted by creation date (the newest are on the top).
Solution:
Run the following PHP-code on a site::
<?php
/*http://drupal.org/node/75781
Shows a list of nodes titles sorted out by their creation dates (the newest are on the top). The original snippet didn’t use the secure db_rewrite_sql() function.
*/
$list_no =10;
$sql = “SELECT n.title, n.nid FROM {node} AS n WHERE n.status = 1 AND n.title NOT LIKE ‘301%’ ORDER BY n.changed DESC LIMIT $list_no”;
$result=db_query(db_rewrite_sql($sql));
while ($anode = db_fetch_object($result)) $links[] = l($anode->title, “node/”. $anode->nid);
return theme_item_list($links);
?>