====== Drupal得到同时属于两个term的节点 ====== ===== 显示同时属于两个term的节点 ===== 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 * shape * square (1) * circle (2) * colour * red (3) * blue (4) (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); ===== 统计节点数 ===== 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 );} ?> ===== 参考 ===== * http://drupal.org/node/59112 * http://drupal.org/node/262202