Fix for Theme function to render a Taxonomy tree as nested lists

  1. function theme_taxonomy_tree($vid) {
  2.   $terms = taxonomy_get_tree($vid);
  3.   $tree = array();
  4.   $items = array();
  5.   foreach($terms as $term) {
  6.     $items[$term->tid]['data'] = theme('term_in_tree', $term);
  7.     $tree[$term->tid] =& $items[$term->tid];
  8.     foreach($term->parents as $parent_tid) {
  9.       if($parent_tid != 0) {
  10.         unset($tree[$term->tid]);
  11.         $items[$parent_tid]['children'][$term->tid] =& $items[$term->tid];
  12.       }
  13.     }
  14.   }
  15.   return theme('item_list', array_values($tree));
  16. }
  17.  
  18. function theme_term_in_tree($term) {
  19.   return l($term->name, taxonomy_term_path($term));
  20. }
  21.  
  22. function MYMODULE_theme($existing) {
  23.   return array(
  24.     'taxonomy_tree' => array(
  25.       'arguments' => array('vid' => NULL),
  26.     ),
  27.     'term_in_tree' => array(
  28.       'arguments' => array('term' => NULL),
  29.     ),
  30.   );
  31. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.