Display a list of (x) node titles and links to the full node from multiple taxonomy/category terms

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.

PLEASE NOTE! The following snippet is 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 from specific multiple categories
* with a link to each node.
*
* To change which taxonomies are listed, simply edit
* $taxo_id1 which is the first taxonomy term referenced
* $taxo_id2 which is the second taxonomy term referenced
* $taxo_id3 which is the third taxonomy term referenced
*
* To change the number of node titles listed, simply edit
* the $list_no number.
*
* This works with Drupal 4.5, Drupal 4.6 and Drupal 4.7
* updated 24-jan-2006.
*/
$taxo_id = 1;
$taxo_id2 = 2;
$taxo_id3 = 3;
$list_no =20;
$sql = "SELECT node.title, node.nid FROM node INNER JOIN term_node ON node.nid = term_node.nid WHERE (term_node.tid = $taxo_id OR $taxo_id2 OR $taxo_id3) 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;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.