Print a list of terms with the number of nodes

Prints a list of terms with the number of nodes in that cat

e.g

Menus
- Lunch (5)
- Dinner (6)
- Wine (4)

Paste into a block or where ever you would like a list of terms

Snippet:
<?php
$vid
= 1; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid);
print
"<div class=\"item-list\">";
print
"<ul>";
foreach (
$terms as $term ) {
$tcount = taxonomy_term_count_nodes($term->tid);
print
"<li>".
l($term->name." (".$tcount.")",'taxonomy/term/'.$term->tid, array('title' => $tcount." posts in ".$term->name)).
"</li>";
}
/* end foreach */
print "</ul>";
print
"</div>";
?>

Comments

leanazulyoro

thanks, this aproaches prett much what i wanted. here’s what i want to do: i installed the og galleries module, it creates a new vocabulary with the name of the group, and terms in that vocabulary for each gallery, is there a way to make this block display the correspondent vocabulary for each group?
i believe there shopuld be a way of doing this by adding some more code here: $vid = ” the vocabulary for current group”.
i don’t have the apropiate php skills to do it, do you think this can be done? thanks, have a nice year