I'm using a multi-level vocabulary and displaying that vocabulary's menu in a block. I've overridden taxonomy/term/* with a custom view which I assigned taxonomy_menu to use. My problem was that if I clicked on a node's term directly it took me to taxonomy/term/x which would not expand the taxonomy_menu appropriately. So I pulled some code out of taxonomy_menu module and modified it to put it in my view's header:

 if( arg(0)== 'taxonomy') {
$vid = 2;  //I'm only interested in vocabulary 2 for my site
$path = variable_get('taxonomy_menu_display_page', 'category') .'/'. $vid;
$tree = taxonomy_get_tree($vid);
$old_depth = -1;
$old_path = $path;
// Generate the entire breadcumb
foreach ($tree as $term) {
  if ($term->depth <= $old_depth) {
    $slashes_to_remove = $old_depth - $term->depth + 1;
    for ($i = 0; $i < $slashes_to_remove; $i++) {
      $old_path = substr($old_path, 0, strrpos($old_path, "/"));
    }
  }
  
$path       = $old_path .'/'. $term->tid;
  $old_depth  = $term->depth;
  $old_path   = $path;
  // When we reach the term that this node uses,
  // set the breadcumb
  if ($term->tid == arg(2)) {
    drupal_goto($path);
    
  }
}
} 

Now if someone clicks on a term that takes them to taxonomy/term/x, it will redirect them to the appropriate taxonomy_menu path, which will then embed this view. As a result, the taxonomy_menu menu items will expand appropriately.

Comments

messenger’s picture

very handy
thanks for posting

summit’s picture

Could this be used for this request please: http://drupal.org/node/302394?
Depending on depth different template?
Could somebody please make a snippet from this outside views?

Thanks a lot in advance!

greetings,
Martijn

arlinsandbulte’s picture

Status: Active » Fixed

I think I saw somewhere this has been fixed... or at least there is a duplicate somewhere.

summit’s picture

It would be nice if you would link to the solution before setting this to fix please.. thanks in advance,
greetings, Martijn

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.