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

/ Published in: PHP
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3. * Lists terms for a specific vocabulary without descriptions.
  4. * Each term links to the corresponding /taxonomy/term/tid listing page.
  5. */
  6. $vid = 1;
  7. $items = array();
  9. $terms = taxonomy_get_tree($vid, 0, -1, 1);
  10. foreach($terms as $term){
  11. $items[]= l($term->name, "taxonomy/term/$term->tid");
  12. }
  13. if(count($items)) {
  14. return theme('item_list',$items);
  15. }
  16. ?>


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.