Submitted by Drupal on Wed, 08/20/2008 - 23:12
UPDATE: Yes, you now can use views to create a list of taxonomy terms. Updated versions of views allow you to choose the view type -which is no longer limited to 'node', you can now select from several different types of 'views' output - excellent!
If you, like me, thought that you could use the "views" module to create a list of all of the taxonomy terms in a certain category - you can't. Views only displays lists of nodes. So, here is the snippet of code that you need to create to that list of links (you could put it in a block):
<?php
$vid = 2; // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {
$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) ) { print theme('item_list', $items);}
?>Tags: