result contains the raw field data $nodes_by_tid = array(); foreach($view->result as $index => $node_fields) { $nodes_by_tid[$node_fields->term_data_tid][] = $rows[$index]; } // Create a category list indexed by parent. i.e. Parent/child term map $subcategories = array(); $tree = taxonomy_get_tree($view->result[0]->term_data_vid); foreach($tree as $taxonomyobject) { foreach($taxonomyobject->parents as $parent) { $subcategories[$parent][] = $taxonomyobject; } } if ($nodes_by_tid) { print _phptemplate_rendertree($subcategories, $nodes_by_tid); } /** * Recursive function to render nested display tree */ function _phptemplate_rendertree($subcategories, $nodes_by_tid, $taxonomy_term = NULL) { if ($taxonomy_term) { $tid = $taxonomy_term->tid; $head = ''; } else { $tid = 0; } // Items for this term $term_item_output = ''; if ($nodes_by_tid[$tid]) { foreach ($nodes_by_tid[$tid] as $item) { $term_item_output .= $item; } } // Subcategories of this term $subcategory_output = ''; if ($subcategories[$tid]) { foreach($subcategories[$tid] as $term) { $subcategory_output .= _phptemplate_rendertree($subcategories, $nodes_by_tid, $term); } } if ($term_item_output || $subcategory_output) { $output = $head . $term_item_output . $subcategory_output . $tail; } return $output; } ?>