Display Drupal taxonomy tree I sucessfully printed the whole taxonomy tree using this code.

$voc = taxonomy_vocabulary_machine_name_load('product_sub_categories');
$tree = taxonomy_get_tree($voc-&gt;vid, 0, NULL, TRUE);
foreach ($tree as $key =&gt; $term) {
  print $term-&gt;name."&lt;/br&gt;";
}


Now I want to separately print parent and child in order to custom theme them, because I already have a mark-up in which parent has separate  &lt;p class="parent_class"&gt; Parent terms&lt;/p&gt; and children has separate &lt;ul class="child_class"&gt;Child terms&lt;/ul&gt;.

How should I do this?



I have done it using taxonomy_get_children(), but it is giving me the children of parent of the taxonomy whose ID is 1.


child1                                                          
child2                                                       
child3


This is what I need, but now I want to get the children of parent 
child1. I tried to get them by reusing the above function but it give me this.


child1


children of child1

child1                                                         
child2                                                        
child3
Use nested foreach like below.


$terms = taxonomy_get_children(1);
foreach ($terms as $term) {
  $items[] = $term->name;
  $child_term = taxonomy_get_children($term->tid);
  if (!empty($child_term)) {
    foreach ($child_term as $child) {
      $items[] = $child->name;
    }

  }
}
return theme('item_list', array('items' => $items));