Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function termpage_nav($term, $settings){
  2.     // the trail is the collection of terms that connect the top level to
  3.     // the currently active term
  4.     $trail = $term ? array_reverse(taxonomy_get_parents_all($term->tid)) : array();
  5.  
  6.     // the settings specific to this block
  7.     $vid = $settings[TERMPAGE_SETTINGS_VID];
  8.     $max_depth = $settings[TERMPAGE_SETTINGS_MAXDEPTH];
  9.  
  10.     // the depth in the tree of the currently active term
  11.     // - 1 to match the depth starting at 0 in the for loop
  12.     $current_depth = count($trail) - 1;
  13.  
  14.     // the collection of terms that make up the trail. One term per level
  15.     $levels = array();
  16.     // variable used for taxonomy_get_tree
  17.     $parent = 0;
  18.    
  19.     // depth 0 means first level
  20.     for($depth = 0; $depth < $max_depth; $depth += 1){
  21.        
  22.         $current = taxonomy_get_tree($vid, $parent, 1);
  23.  
  24.         // some additional info for the template
  25.         termpage_add_alias($current);
  26.         $active = $depth <= $current_depth ? $trail[$depth]->tid : null;
  27.  
  28.         $parent = $active;
  29.        
  30.         $levels[$depth] = array(
  31.             'terms'  => $current,
  32.             'active' => $active,
  33.         );
  34.     }
  35.     return $levels;
  36. }