nomeer
nomeer

Reputation: 205

Display Drupal taxonomy tree

I sucessfully print the whole taxonomy tree through this code
$voc = taxonomy_vocabulary_machine_name_load('product_sub_categories'); $tree = taxonomy_get_tree($voc->vid,0,NULL,TRUE); foreach ($tree as $key => $term){ print $term->name."</br>"; } , now I want to separatly print parent and chile in order to custon theme them, because I have already a markup in which parent has separate <p class="parent_class">Parent terms</p> and children has separate
<ul class="child_class">Child terms</ul>. How should I do this, can anyone there to help me?

Upvotes: 0

Views: 436

Answers (2)

nomeer
nomeer

Reputation: 205

Here is the solution

`$tree=taxonomy_get_children(1);
foreach ($tree as $term)
{
$item[] = $term->name;
$child_term = taxonomy_get_children($term->tid);
if (!empty($child_term))  
{
print $term->name."<br>";
foreach ($child_term as $child) 
{
print $child->name."<br>";
}
}
else 
print $term->name."<br>";
}`

Upvotes: 1

Uzma Abdul Rasheed
Uzma Abdul Rasheed

Reputation: 60

You can use the Views Tree Module.

Here is the documentation for this module https://www.drupal.org/node/1493366

Upvotes: 0

Related Questions