The bellow comes from thread http://drupal.org/node/133223
split out taxonomy terms by vocabulary.
It works But it only shows the bottom level of taxonomy terms.
The Question I have is how do I use the second code combined with this code?
Because the second snippet spits out the terms correctly just in one long vertical list with no vocabularies.
function my_theme_print_terms($nid) {
$vocabularies = taxonomy_get_vocabularies();
$output = '<ul>';
foreach($vocabularies as $vocabulary) {
if ($vocabularies) {
$terms = taxonomy_node_get_terms_by_vocabulary($nid, $vocabulary->vid);
if ($terms) {
$links = array();
$output .= '<li>' . $vocabulary->name . ': ';
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= '</li>';
}
}
}
$output .= '</ul>';
return $output;
}
This is the address of my site with the above code. http://bowwowimport.com/products/boge-pro-gas-front-strut-insert.
- Auto Parts: Suspension
- Car Manufacturer: 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1989, 1988, 1987, 1992, 1991, 1990, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1989, 1988, 1987, 1986, 1985, 1989, 1988, 1987, 1992, 1991, 1990, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985
- Manufacturers: Boge
what I want to use as part of this code but I need to have the $vocabularies = taxonomy_get_vocabularies();
and show all the parents under Car Manufacturer formatted like the above code does but with all the parents of the years .
and this is how the above code outputs the taxonomy.
my taxonomy is like this:
Car Manufacturer is the vocabulary
-volkswagen
--Jetta
---MKIII
----1999
----1998
----1997
----ETC
---MKIV
----2003
----2002
----ETC
The nodes fit multiple years of different models but not always the same years.
function my_theme_print_terms($nid) {
$terms = taxonomy_node_get_terms($nid);
$links = array();
$processed = array();
if($terms){
foreach($terms as $term){
$parents = taxonomy_get_parents_all($term->tid);
foreach($parents as $parent){
if(!in_array($parent->tid, $processed)){
$links[] = l($parent->name, taxonomy_term_path($parent), array('rel' => 'tag', 'title' => strip_tags($parent->description)));
$processed[] = $parent->tid;
}
}
}
$output = theme('item_list', $links);
return $output;
}
}
I am getting close to getting this.
Thanks Eric (bowwowadmin)
Remember always keep the sun on your back and Drupal in your face :)
Comments
This is what I'm doing to show related terms . . .
I've only documented the stuff I added. I did this directly in a node.tpl file replacing the
<span class="taxonomy"><?php print $terms?></span>line instead of going through the template.php.I took part of my code from here: http://drupal.org/node/53089. Also, it works only if there is one vocabulary involved. If there are two or more, it creates a "See also:" line for every vocabulary. I'm working on a version to correct this problem.
More than 1 category on a node
This is for those cases where a node has a list of related terms with spanning over 2 or more categories. I've only documented the changes from above.
Subscribing, greetings,
Subscribing, greetings, Martijn
Take a look here
After I posted the code here, I ended up writing a snippet page at http://drupal.org/node/265502 that dealt with not only the single and multiple vocabularies, but multiple hierarchies as well.