Community Documentation

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

Last updated January 8, 2007. Created by pwolanin on January 26, 2006.
Edited by travischristopher. Log in to edit this page.

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;
?>

About this page

Drupal version
Drupal 4.5.x or older, Drupal 4.6.x, Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.