Taxonomy Tree with feed links
PLEASE NOTE: The php snippets are user submitted and it is impossible to check every one, so use at your own risk. When using an alternate database to the default MySQL, some database queries may not work.
This little code outputs the full taxonomy tree, including the number of nodes and feed link for each term.
<?php
function get_child_terms($parent, $vid) {
$sql = "SELECT td.tid, td.vid, td.name"
. " FROM {term_data} td"
. " JOIN {term_hierarchy} th on th.tid = td.tid"
. " WHERE th.parent = %d"
. " AND td.vid = %d"
. " ORDER BY td.weight, td.name";
$terms = db_query($sql, $parent, $vid);
$output = "";
while ($aterm = db_fetch_object($terms)) {
$output .= "<li>";
$output .= theme('feed_icon', url("taxonomy/term/$aterm->tid/all/feed"))
. " "
. l("$aterm->name", "taxonomy/term/$aterm->tid/all") . " ("
. taxonomy_term_count_nodes($aterm->tid) . ")</li>\n"
. get_child_terms($aterm->tid, $vid);
}
return ($output != "") ? "<ul>\n". $output ."</ul>\n" : "";
}
$sql = "SELECT vid, name FROM {vocabulary} ORDER BY name";
$vocabularies = db_query($sql);
$output = "";
while ($avoc = db_fetch_object($vocabularies)) {
$output .= "<li><strong>$avoc->name</strong></li>\n"
. get_child_terms(0, $avoc->vid);
}
print "<div class='taxonomy_tree'><p><ul>\n". $output ."</ul></p></div>\n";
?>With a little CSS style like this we can avoid showing list bullets, and also customize list margins:
.taxonomy_tree ul {
list-style-type: none;
margin: 0px 0px 0px 20px;
padding: 0px;
}I haven't find any module or code to do this simple thing, so I wrote it and I hope you guys like it.
You can see it working at http://spaniards.es/indice (the url alias requires path module).
