Loop all terms in a vocabulary

  <?php

function list_all_countries($vid) {
$vid = 1// Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$pole = array();
$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));
 
$pole[]=Array (l($term->name, "taxonomy/term/$term->tid") . " ($count)", $term->depth, $count, $term->tid)  ;
}
 
$depth =-1;
  foreach (
$pole as $list) {
    if (
$list[1] > $depth) echo "\n<ul>";
    if (
$list[1] < $depth) echo "\n</li>\n</ul>\n</li>";
    if (
$list[1] == $depth) echo "</li>";
   
$poc++;
    echo
"\n<li>$list[0]";

if (
$list[2]>0) {
      echo
"\n<ul>";
     
$result = db_query("SELECT * FROM {term_node} WHERE tid=$list[3]");
      while(
$zaznam = db_fetch_array($result)) {
       
$node = db_result(db_query("SELECT title FROM {node} WHERE nid=$zaznam[nid]"));
       
$node_link = l($node, "node/$zaznam[nid]");
        echo
"\n<li>$node_link</li>";
      }
      echo
"\n</ul>";
  }
   
$depth=$list[1];
}
echo
"</li>\n</ul>";
 
}

?>
 
Knowledge keywords: