Drupal print Vocabularies and Terms associated with a node


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



Copy this code and paste it in your HTML
  1. In template.php
  2.  
  3. <?php
  4. function mythemename_taxonomy_links($node, $vid) {
  5.  
  6. //if the current node has taxonomy terms, get them
  7. if (count($node->taxonomy)):
  8.  
  9. $tags = array();
  10. foreach ($node->taxonomy as $term) {
  11. if ($term->vid == $vid):
  12. $tags[] = l($term->name, taxonomy_term_path($term));
  13. endif;
  14. }
  15. if ($tags):
  16. //get the vocabulary name and name it $name
  17. $vocab = taxonomy_get_vocabulary($vid);
  18. $name = $vocab->name;
  19. $output .= t("$name") . ": " . implode(' | ', $tags);
  20. endif;
  21.  
  22. endif;
  23.  
  24. if ($output):
  25. return $output;
  26. endif;
  27.  
  28. }
  29. ?>
  30.  
  31. In page.tpl.php
  32.  
  33. <?php
  34. $nid = arg(1);
  35. print yourthemename_print_terms($nid);
  36. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.