This PHP snippet displays all top-level taxonomy terms in a page or a block.
For each term, the count of sub-terms is displayed.
The code is using the taxonomy API, so it's compatible with taxonomy_redirect (verified). It should also be compatible with other add-on modules which change the term path.
<?php
$vid = 3;
$terms = taxonomy_get_children(0, $vid);
if (count($terms)) {
echo '<ul>';
foreach ($terms as $term){
echo "<li>" . l($term->name, taxonomy_term_path ($term)) ;
$children = taxonomy_get_children($term->tid, $vid);
$cnt = count($children);
if ($cnt) echo " ($cnt)";
echo "</li>";
}
echo '</ul>';
}
?>