how to display Node Terms in block with tree structure in Drupal?

Events happening in the community are now at Drupal community events on www.drupal.org.
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,

Categories: , ,

Comments

jquery tree

Posted by lakshminp on April 7, 2011 at 4:52pm

jquery tree for administer menu

Posted by gobinathm.php on April 8, 2011 at 8:27am

will it support for node terms?

Views

Posted by naushunaushad on April 8, 2011 at 5:38am

You can create block views

can you guide me a step

Posted by gobinathm.php on April 8, 2011 at 8:29am

How it will display like a tree structure terms for that particular node, can you guid e with simple steps

Try this..

Posted by rajarju on April 12, 2011 at 7:36am

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

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /