Вывести термины словаря таксономии в виде дерева
Имеется словарь tags:
Задача — вывести термины этого словаря в виде дерева:
Код:
/**
* Return rendered taxonomy tree
*/
function mymodule_taxonomy_tree($vocabulary_name) {
$vid = taxonomy_vocabulary_machine_name_load($vocabulary_name)->vid;
$terms = taxonomy_get_tree($vid);
return theme('item_list', array('items' => _mymodule_taxonomy_tree($terms)));
}
/**
* Helper for mymodule_taxonomy_tree()
*/
function _mymodule_taxonomy_tree($terms, $parent = 0) {
$items = array();
foreach ($terms as $term) {
if (in_array($parent, $term->parents)) {
$items[] = array(
'data' => $term->name,
'children' => _mymodule_taxonomy_tree($terms, $term->tid),
);
}
}
return $items;
}
Использование:
echo mymodule_taxonomy_tree('tags');
Написанное актуально для
Drupal 7
Комментарии:
Нету комментариев для вывода...