Submitted by drupaliran on Sat, 08/25/2007 - 06:02.
I use this code:
<?php
$vid = 4; // 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 = "<span>(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")</span>"; $items[] = l($term->name, "taxonomy/term/$term->tid") . " $count"; } if ( count($items) ) { print theme('item_list', $items);} ?>
Since I found the taxonomy_get_tree function returns the depth of each node, I modified the supplied code above like so:
<?php $vid = 4; // 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)).")"; $termdepth = ""; for ($i=0;$i<$term->depth;$i++) { $termdepth = $termdepth . "-- "; } $items[] = $termdepth . l($term->name, "taxonomy/term/$term->tid") . " $count"; } if ( count($items) ) { print theme('item_list', $items);} ?>
Specifically, adding the inner for...loop to add the -- characters one time for each depth level. If you have too many levels and you don't want to return them all to this list, then call taxonomy_get_tree with the fourth parameter being the max depth.
I use this code
I use this code:
<?php
$vid = 4; // 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 = "<span>(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")</span>";
$items[] = l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) { print theme('item_list', $items);}
?>
here is a demo(right column-second block):
http://www.iran-amirentezam.com
N.Mehrabany
niGraphic web design & photography
something which shows the hierarchy of the taxonomy
Since I found the taxonomy_get_tree function returns the depth of each node, I modified the supplied code above like so:
<?php$vid = 4; // 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)).")";
$termdepth = "";
for ($i=0;$i<$term->depth;$i++)
{
$termdepth = $termdepth . "-- ";
}
$items[] = $termdepth . l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) { print theme('item_list', $items);}
?>
Specifically, adding the inner for...loop to add the -- characters one time for each depth level. If you have too many levels and you don't want to return them all to this list, then call taxonomy_get_tree with the fourth parameter being the max depth.