Display a list of (x) node titles including links to their respective categories

Last modified: January 8, 2007 - 21:48

I've only tested this in 4.6, but i'm assuming it'll work in other versions. This works well as a page or a block

format works like so

Node title - Category

<?php
/**
* Creates a list of node titles from specific multiple categories
* with a link to each node and a link to the taxonomy term
*
* 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 25-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)) {
     
$links = array();
      foreach (
taxonomy_node_get_terms($anode->nid) as $term) {
       
$links[] = l($term->name, 'taxonomy/term/'. $term->tid);
      }
     
$output .= "<li>" . l($anode->title, "node/$anode->nid") . ' - ' . theme('links', $links) . "</li>";
}
$output .= "</ul>";
print
$output;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.