Show a list (x) of taxonomy terms with node counts
Last modified: November 1, 2009 - 18:30
This simple block snippet displays a list of taxonomy terms in alphabetical order. Each term links to the term's page.
<?php
$vid = 11;
$num_term = 20;
$query = "SELECT tid, name from {term_data} WHERE vid=$vid ORDER BY name ASC LIMIT $num_term";
$result = db_query($query);
while ($term = db_fetch_object($result)) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));
$items[]= l($term->name, "taxonomy/term/$term->tid") . '(' . $count . ')';
}
if(count($items)) {
return theme('item_list',$items);
}
?>The result will looks like this:
