Hi,

I a Drupal newbie, especially when it comes to theming and taxonomy.

I want to print the terms associated with a node. I aready know about print Sterms. However, that doesn't do what I want, since I want to print only those terms that belonging to a given vocabulary.

Suppose I have nodes of the type article and a free tagging vocabulary authors. In the template node-article.tpl.php, I want be able to include something like print $authors to display the author's name.

How can I determine which terms of authors, bearing in mind there could be more than one author per article, are associated with a given article node?

I searched the web but didn't find an answer to this question.

TIA,

cliftoo

Comments

carlmcdade’s picture

You can use this function in your template or create a new module

http://api.drupal.org/api/function/taxonomy_node_get_terms_by_vocabulary/6

function taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = 'tid') {
  $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.vid = %d ORDER BY weight', 't', 'tid'), $vid, $node->vid);
  $terms = array();
  while ($term = db_fetch_object($result)) {
    $terms[$term->$key] = $term;
  }
  return $terms;
}

Hiveminds Magazine | FireOrb | Drupal Street | Drupal offline manual