I want to display the terms of some vocabualry as an ul. and I want to count the nodes that are related to these terms and another term I define.

just like adding another term arg in the taxonomy/term view. I mean "taxonomy/term/term"

I tried writing the code ...


$vid = 106 ;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$parent = 204; 
$items = array();
$terms = taxonomy_get_tree($vid, $parent);
$term2 = 340; // this is the second term we're going to count nodes for
foreach ( $terms as $term ) {  // $term here is the first 
$count = 0;
$query = 'SELECT * FROM  {term_node} WHERE tid = '. $term->tid;
$result = db_query($query);
while ($term_array = db_fetch_array($result)) {
	$nidd = $term_array['nid'] ;
	$query2 = 'SELECT * FROM {term_node} WHERE nid = ' . $nidd . ' AND tid = ' . $term2 ;
	while ($aa = db_num_rows(db_query($query2))) {
	 $count =+ 1;

	}
}
    $items[] = l($term->name . ' (' . $count . ')', "results/terms/$term->tid/$termOfTheYear" );
}
if ( count($items) ) {  print theme('item_list', $items );}

but I have a problem in the counting part. I couldn't figure out why the $count variable always returns the value "1" even whene the nodes that has the terms "term and term2" are mode than one.

Comments

gpk’s picture