Render Taxonomy Terms based on Vocab ID


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



Copy this code and paste it in your HTML
  1. function render_terms($node,$vocabid,$title=null,$divclass=null) {
  2.  
  3. $terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabid );
  4. if ($terms) {
  5.  
  6. $output = '<div class="field field-item'. ' '.$divclass .'"><div class="field-label-inline-first">' .$title .' </div> ' ;
  7. $term_links = array();
  8. foreach ($terms as $term) {
  9. $term_links[] = l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)))) ;
  10. $output .= implode(", ", $term_links);
  11. }
  12. }
  13. $output .='</div>';
  14. return ($output);
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.