List of terms from a specific vocabulary that are applied to a node

Comma separated list of terms within a specific vocabulary that are applied to the current (or some other) node

I have some event-type nodes (CCK) listing upcoming entertainment. They have two vocabularies applied to them; venue and genre. 3 is the vid of the "genre" vocabulary, so it appears here in my example. It uses taxonomy functions as appropriate, no SQL here. Just change the number '3' in the taxonomy_node_get_terms_by_vocabulary function call to the id of the vocabulary you would like to query.

<?php

$firstterm
= 0;
foreach ((array)
taxonomy_node_get_terms_by_vocabulary($nid, 3, $key = 'tid') as $term) {
  if (
$firstterm > 0 ) {
    print
", ";
  }
  print
"<a href=\"" . taxonomy_term_path($term) . "\">$term->name</a>";
 
$firstterm++;
}
?>

Further little notes: As you can see it uses $nid for the node-id. You can print a list of the terms for any node by specifying its nid here. This simply returns the terms for the current node. I used this code in a contemplate.

 
 

Drupal is a registered trademark of Dries Buytaert.