views:

274

answers:

2

Hey all,

I'm looking to generate a hierarchical breadcrumb from a taxonomy term (e.g. grandparent/parent/child) when all I have is the TID of "child". I've been toying around with taxonomy_get_tree(), but it seems quite difficult to do without very heavy iteration. There has to be an easier way.

Thoughts?

Thanks!

+3  A: 

Taxonomy Breadcrumb seems to provide this functionality.

If you don't want to use the module, the code might provide inspiration.

Grayside
+1  A: 

This is what I do:

$breadcrumb[] = l(t('Home'), NULL);
if ($parents = taxonomy_get_parents_all($tid)) {
  $parents = array_reverse($parents);
  foreach ($parents as $p) {
    $breadcrumb[] = l($p->name, 'taxonomy/term/'. $p->tid);
  }
}
drupal_set_breadcrumb($breadcrumb);

I'll typically stick this in a hook_view() function or hook_nodeapi($op="view") function.

Nathan Rambeck
Answer credit for pointing me to taxonomy_get_parents_all(). Thanks!
cpharmston