Block that displays terms in a vocabulary as a list of links

Last modified: November 8, 2008 - 21:39

This is a simple little block that displays a list of terms in a vocabulary as a list of links to /taxonomy/term/tid pages. Items are listed in the order set for the vocabulary. You could probably use the php sort() function to change that if desired.

Be sure to change the $vid to reflect the vocabulary id of the vocabulary you wish to list. Also, you can change the "taxonomy/term/$term->tid" to any path you wish.

<?php
/**
* Lists terms for a specific vocabulary without descriptions.
* Each term links to the corresponding /taxonomy/term/tid listing page.
*/
$vid = 1;
$items = array();

$terms = taxonomy_get_tree($vid0, -1, 1);
foreach(
$terms as $term) {
 
$items[]= l($term->name, "taxonomy/term/$term->tid");
}
if(
count($items)) {
  return
theme('item_list', $items);
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.