Posted by gobinathm.php on April 7, 2011 at 2:49pm
Hey guys,
I just enabled multiple terms for node creation and i just wanna display those mulitple terms as a tree sturctured in a block i tried with the following code
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
$node = node_load(arg(1));
if (module_exists('taxonomy')) {
$terms = taxonomy_link('taxonomy terms', $node);
print theme('links', $terms, array('class' => 'node-terms'));
} else {
print 'No associated categories.';
}
}
But no luck its just displaying all terms, But i have to display like below
- parent term1
- sub term 1.1
- parent term 2
- sub term 2.1
-- sub sub term 2.1.3
Based on the user selected will display accordingly as a tree in a block on that corresponding node page.
Anyone please help,
Comments
jquery tree
Hi
did you try the jquery tree menu module?
jquery tree for administer menu
will it support for node terms?
Views
You can create block views
can you guide me a step
How it will display like a tree structure terms for that particular node, can you guid e with simple steps
Try this..
Try this approach..
<?php
//hook_theme
function mymodule_theme() {
return array(
'taxonomy_nested_tree' => array(
'arguments' => array(
'tree' => NULL,
'cat_base_url' => 'taxonomy'
)
)
);
}
//$tree = taxonomy_get_nested_tree($cat_id); load this and send the $tree to the theme function
//$cat_base_url is the menu base path that you want for the menu items
function theme_taxonomy_nested_tree($tree , $cat_base_url = 'taxonomy') {
global $base_url;
if (count($tree)) {
$output = '<ul class="catalog taxonomy-tree ">';
foreach ($tree as $term) {
$class = 'taxonomy-term ';
if (count($term->children))
$class .= 'hasChild';
$output .= '<li class="' . $class . '">';
if(count($term->children) > 0)
$args = $term->tid . "+" . implode("+", array_keys((array) $term->children));
else{
$args = $term->tid;
}
//You will have to change this part to what ever path you want
$output .= l($term->name, "$base_url/$cat_base_url/$args");
if ($term->children) {
$output .= theme('taxonomy_nested_tree', $term->children, $cat_base_url);
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
?>
rajarju