Display a list of (x) node titles of a specific type
Last modified: April 11, 2007 - 18:57
PLEASE NOTE! The following snippets are user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
<?php
/**
* Creates a list of node titles of a specific type
* with a link to each node.
*
* To change which type is listed, simply edit the $node_type string.
* To change the number of node titles listed, simply edit the $list_no number.
*
* This works with Drupal 4.5 and Drupal 4.6
*/
$node_type = "flexinode-1";
$list_no =5;
$sql = "SELECT node.title, node.type, node.nid FROM {node} WHERE node.type = '$node_type' LIMIT $list_no";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
print $output;
?>To list them in descending order
<?php
/* list of recent posts of node type 'flexinode-1'
** output in descending chronological order
*/
unset ($output); // clear previous output
$node_type = "flexinode-1";
$list_no =5;
$sql = "SELECT node.title, node.type, node.nid FROM {node} WHERE node.type = '$node_type' AND node.status = 1 ORDER BY node.created DESC LIMIT $list_no";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
print $output;
?>