Community Documentation

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

Last updated November 8, 2008. Created by Barrett on April 16, 2008.
Edited by WorldFallz. Log in to edit this page.

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

About this page

Drupal version
Drupal 4.6.x, Drupal 4.7.x, Drupal 5.x, Drupal 6.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.