<?php
function taxonomy_get_nested_tree($terms = array(), $max_depth = NULL, $parent = 0, $parents_index = array(), $depth = 0) {
$return = array();
if (is_int($terms)) {
$terms = taxonomy_get_tree($terms);
}
foreach($terms as $term) {
foreach($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}
}
}
foreach($return as &$term) {
if (isset($parents_index[$term->tid]) && !is_null($max_depth) && $depth < $max_depth) {
$term->children = taxonomy_get_nested_tree($parents_index[$term->tid], $max_depth, $term->tid, $parents_index, $depth + 1);
}
}
return $return;
}
<?php
$vid = 1; // Словарь
$pole = array();
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));
$pole[]=Array (l($term->name, "taxonomy/term/$term->tid") . "", $term->depth, $count, $term->tid) ;
}
$depth =-1;
foreach ($pole as $list) {
if ($list[1] > $depth) echo "\n<ul>";
if ($list[1] < $depth) echo "\n</li>\n</ul>\n</li>";
if ($list[1] == $depth) echo "</li>";
$poc++;
echo "\n<li>$list[0]";
if ($list[2]>0) {
echo "\n<ul>";
$result = db_query("SELECT * FROM {term_node} WHERE tid=$list[3]");
while($zaznam = db_fetch_array($result)) {
$node = db_result(db_query("SELECT title FROM {node} WHERE nid=$zaznam[nid]"));
$node_link = l($node, "node/$zaznam[nid]");
echo "\n<li>$node_link</li>";
}
echo "\n</ul>";
}
$depth=$list[1];
}
echo "</li>\n</ul>";