Python俱乐部
Python
小课题
京东优惠券
The following code uses the taxonomy api to render a listing of nodes that belong to terms to more than one category. For example, if i have two taxonomies
(term ids are in brackets) the following code would return a list of nodes classified as blue squares:
$myNodes = taxonomy_select_nodes(array(4,1),"and"); print taxonomy_render_nodes($myNodes);
This can be modified to a list of all blue shapes and squares by changing the “and” to “or”:
$myNodes = taxonomy_select_nodes(array(4,1),"or"); print taxonomy_render_nodes($myNodes);
<?php $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 );} ?>