跳至内容
Python 俱乐部
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
drupal:script:two-terms
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== 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: <code php> $myNodes = taxonomy_select_nodes(array(4,1),"and"); print taxonomy_render_nodes($myNodes); </code> This can be modified to a list of all blue shapes and squares by changing the "and" to "or": <code php> $myNodes = taxonomy_select_nodes(array(4,1),"or"); print taxonomy_render_nodes($myNodes); </code> ===== 统计节点数 ===== <code php> <?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 );} ?> </code> ===== 参考 ===== * http://drupal.org/node/59112 * http://drupal.org/node/262202
drupal/script/two-terms.txt
· 最后更改: 2010/06/02 01:18 (外部编辑)
页面工具
显示页面
修订记录
反向链接
回到顶部