I sucessfully printed the whole taxonomy tree using 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 separately print parent and child in order to custom theme them, because I already have a mark-up 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?
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