Code below prints the terms in a particular vocabulary associated with the node.

You can just copy and paste the code in a block. Do not forget to change $vid value for the vocabulary.

To get $vid value for your vocabulary, just go to admin/content/taxonomy and mouse over the "edit vocabulary" link for the vocabulary you want to print. You can see vid at the status bar - the number which is at the end of the path.

/**
 * Prints an unordered list of the terms (as links) that are
 * associated to the currently displayed node.
 */
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    $node = node_load(arg(1));
    $vid = 2;
    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    if ($terms) {
print '<ul>';
                foreach ($terms as $term) {
                print '<li>'.l($term->name, 'taxonomy/term/'.$term->tid).'</li>';

          }
print '</ul>';
    } 
}

Comments

netentropy’s picture

Great snippet but how would one only call the first term instead of all terms.

trevorkjorlien’s picture

This snippet worked really good on one of my content types (locations) where I needed the info at the END of the node.

But now I want to print a term near the top of a node (the slug for an article). When I insert the code before the content, the term shows up, but the node doesn't print the rest of the content.

I'm not a PHP developer, but does anybody see how this code would break printing the rest of the content?

leisurman’s picture

olafveerman,

How would this statement be written if you want to remove the list style ul and li classes. I tried myself but messed up the syntax.