Is there some elegant way how to show tags, categories separated?
anantagati - November 14, 2006 - 11:22
Hi, I am using in site with few vocabularies.
Is there some elegant way how to format in theme for node showing of tags, categories?
For example:
Instead of something like this:
term1_in_voc1 tag3_in_voc4 term2_in_voc1 tag2_in_voc4 tag1_in_voc4I need that I can put terms from each vocabulary separate or that some vocabularies will not be shown:
VOC1: term1_in_voc1 term2_in_voc1
VOC4: tag3_in_voc4 tag2_in_voc4 tag1_in_voc4or only
VOC4: tag3_in_voc4 tag2_in_voc4 tag1_in_voc4Thank you for help

Just bookmarking. I'm also
Just bookmarking. I'm also curious.
Anisa.
-----------------------------------------------------------
Kindness builds stronger bonds than necessity.
www.animecards.org - 18,000 card scans and counting!
-----------------------------------------------------------
My function
Hi,
I wrote a function which does just this. I put it in my template.php, but you could just as easily (and perhaps more properly) put it in a custom module.
<?php
/**
* Return a list of taxonomy terms with each vocab on its own line.
*/
function node_terms_list($node) {
$output = '<p class="terms">';
$vocabularies = taxonomy_get_vocabularies();
foreach($vocabularies as $vocabulary) {
if ($vocabularies) {
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocabulary->vid);
if ($terms) {
$output .= '<strong>' . $vocabulary->name . ':</strong> ';
foreach ($terms as $term) {
//$output .= l($term->name, 'taxonomy/term/'.$term->tid) . ', '; //with link
$output .= $term->name . ', ';
}
$output = trim ($output,", ").'<br />';
}
}
}
$output .= '</p>';
return $output;
}
?>
You'll see I've commented out a line above. This allows you to choose whether you want the taxonomy terms to link to taxonomy overview pages or not. As it is above it won't link.
Call this from your node.tpl.php (or elsewhere) like so:
<div class="taxonomy"><?php print node_terms_list($node); ?>
</div>
Hope this helps.
Jeff
Seperate Vocabularies
Thank you.
Please add this to the snippets in the handbook
Like the subject says...
I ran the Microsoft Malicious Software Removal tool, but Internet Explorer is still installed on my computer.
Nice!
Nice, I have been looking for something like this. I thought there was an easier way. Why are vocabularies not separated in $node?
I haven't found a way so far to change the order of the vocabularies.
Great tip! Thank you!
Jamie Meredith
Web Architect
centre{source} - Nashville, TN
Instructions for Drupal 6.x?
This is exactly what I am trying to accomplish myself but I am using drupal 6.x which these instructions don't appear to work with. Any ideas on how this can be accomplished in drupal 6.x?
Thank you in advance for your help. Sorry to resurrect such an old topic.
Change for Drupal 6
In Drupal 6 the taxonomy_node_get_terms_by_vocabulary() api function has been changed.
See http://drupal.org/node/133223#comment-971965 to get this working for Drupal 6.