使用Drupal API获取与类别术语相关的节点数组 [英] Getting an array of nodes related to a category term with the Drupal API
本文介绍了使用Drupal API获取与类别术语相关的节点数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
AFAIK, taxonomy_select_nodes()
是最接近的一个 - 它不返回字符串,但一个查询资源,所以你可以做你想要的有点像这样:
function yourModule_get_nodes_by_term_id($ tid){
$ nodes = array();
//注意:只能查找一个术语,只有一个级别深入这里!
$ result = taxonomy_select_nodes(array($ tid),'and',0,FALSE);
$ items = array();
while($ row = db_fetch_object($ result)){
$ nodes [] = node_load($ row-> nid);
}
return $ nodes;
}
尽管如此,性能可能会对大量节点产生不利影响: / p>
I have a simple one level deep vocabulary taxonomy. Something like Vocabulary->Term->Node. What I want to know is if there's a built in function to get an array of nodes related to a single term, something like taxonomy_select_nodes() but that would return an array of nodes instead of a string.
解决方案
AFAIK, taxonomy_select_nodes()
is the closest one available - and it does not return a string, but a query resource, so you could do what you want somewhat like so:
function yourModule_get_nodes_by_term_id($tid) {
$nodes = array();
// NOTE: Will lookup by only one term, and only one level deep here!
$result = taxonomy_select_nodes(array($tid), 'and', 0, FALSE);
$items = array();
while ($row = db_fetch_object($result)) {
$nodes[] = node_load($row->nid);
}
return $nodes;
}
The performance could get pretty bad for large numbers of nodes, though :/
这篇关于使用Drupal API获取与类别术语相关的节点数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文