All pastes #960492 Raw Edit

split out taxonomy terms by pare

public php v1 · immutable
#960492 ·published 2008-03-28 04:24 UTC
rendered paste body
<?php// split out taxonomy terms by parent// $tree =// ( 'Audi' =>//      ( '100' =>//          ( '1.8LS' => (1968, 1969, 1970)//          ( '1.9LS' => (1971, 1969, 1970)//      )// )// $thismake - 'Audi'// $models - ( '100', ('1.8LS' => (1968, 1969, 1970), '1.9LS' =>//(1971, 1969, 1970) ) )//   $thismodel becomes '100'//   $engines - ('1.8LS' => (1968, 1969, 1970)//       $thisengine becomes '1.8LS'//       $years - (1968, 1969, 1970)function bowwowtheme_liquid_print_terms($nid) { $links = array(); $processed = array(); $tree = array(); $terms = taxonomy_node_get_terms($nid); if($terms){   foreach($terms as $term){     $parents = taxonomy_get_parents_all($term->tid);     if (in_array($parents[0]->tid, $processed)){         continue;     } else {       $processed[] = $parents[0]->tid;       array_reverse($parents);       if (4 == count($parents)) {         $tree[$parents[0]->name][$parents[1]->name][$parents[2]->name][]= $parents[3]->name;       } else if (3 == count($parents)) {         // handle the VW case        $tree[$parents[0]->name][$parents[1]->name][]= $parents[2]->name;        }     }   }   // printing   foreach ($tree as $thismake => $models) {     print $thismake . " - ";     foreach ($models as $thismodel => $engines) {       print $thismodel . " - ";       foreach ($engines as $thisengine => $years) {         print $thisengine . " - ";         foreach ($years as $yr) { print $yr . ", "; }       }     }   } }}?>