Sunday, April 18, 2010

Drupal display taxonomy terms for particular vocabulary


$vid = 3; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid); /* need code from below to handle nesting */
print "

    ";
    foreach ( $terms as $term ) {
    $count = db_result(db_query("SELECT DISTINCT COUNT(nid) FROM {term_node} WHERE tid = %d ", $term->tid));
    if ($count) { /* don't show terms with 0 count */
    print "
  • ".l($term->name .' ('. $count .')', "taxonomy/term/$term->tid") ."
  • ";//this creates a link to the term
    }
    } /* end foreach */
    print "
";
?>

0 comments: