Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By neet_khuranas on
hi everyone,
the below code works.
<?php
function getNodeCount($tid)
{
$sql = "select count(1) as num"
. " from term_node"
. " where tid = $tid";
return ($acount = db_fetch_object(db_query($sql)))? $acount->num : 0;
}
function getChildTerms($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 = $parent"
. " and td.vid = $vid"
. " order by td.weight, td.name";
$terms = db_query($sql);
$output = "";
while ($aterm = db_fetch_object($terms))
{
$output .= "<li><a href='taxonomy/term/$aterm->tid/0/feed'></a> "
. "<a href='taxonomy/term/$aterm->tid'>$aterm->name</a> ("
. getNodeCount($aterm->tid).")</li>\n"
. getChildTerms($aterm->tid, $vid);
}
return ($output != "")? "<ul>\n" . $output . "</ul>\n" : "";
}
$sql = "select vid, name from vocabulary where name in ('directory', 'shopping') order by name";
$vocabularies = db_query($sql);
$output = "";
while ($avoc = db_fetch_object($vocabularies))
{
$output .= "<li><strong>$avoc->name</strong></li>\n"
. getChildTerms(0, $avoc->vid);
}
print "<div class='taxonomy_tree'><p><ul>\n" . $output . "</ul></p></div>\n";
?>
but i don't want to get ChildTerms..rather NodeCount should be there but with the parent vocabulary names.Join with tid and vid (of three tables--vocabulary,term_data and term_node) is required.but i don't know how to use them.
Thanks
Comments
Any help is appreciated to
Any help is appreciated to solve this problem.