我一直在努力将节点术语的父项id放在视图参数中。让我解释一下为什么我要做这么奇怪的事情。嗯,在术语页面上,我显示了一个块,其中包含该术语下所有节点的列表。但是当你点击任何节点的时候,这个块就消失了,因为视图中的默认参数(对于term id)是: if (arg(0) == ' taxonomy‘&& arg(2) != '') { return arg(2);}这是用于分类排列,比如team>>Country>>Australia>>特征,文章等。这里:词汇表是团队:国家是主要术语,澳大利亚是子术语,特征,文章等是孩子的子术语。但是,由于我还想在该术语的节点页面上显示Block,所以我想提取该节点的术语的父术语‘I,因为节点是(比方说) Feature下的一篇文章,而我显示的节点列表的块是澳大利亚术语下的。这样我就可以添加更多的参数,比如: elseif(arg(0) == 'node') { then ......请帮帮忙。
发布于 2011-02-23 07:44:41
如果我没理解错的话,您想要显示一个块,其中显示与节点术语的直接父项具有相同分类术语的所有节点。如果节点有两个项a>b (即a是b的父项),则项是a。如果您有a>b>c并且所有项都已设置,则a和b作为某个项的父项。然后,该块必须显示所有以a和b作为术语的节点。
因此,后续部分将是:
else if (arg(0) == 'node' && is_numeric(arg(1)))) {
$n = node_load(arg(1));
$vid = 0; // change for the required vocabulary
$tids = array(); // will hold all the parents of the node's terms
foreach ($n->taxonomy as $tid => $term) {
if ($term->vid == $vid) {
$parents = taxonomy_get_parents($term->tid);
// the term has a parent
if (count($parents)) {
$parent = array_shift($parents);
$tids[] = $parent->tid;
// if you require only one parent term, return the first one that we find
// comment the next line if you want all terms that act as parents
return $parent->tid;
}
}
}
// in this case, make sure that you
// check the 'Allow multiple terms per argument' checkbox
// and argument type is 'Term IDs separated by , or +'
return implode(',', array_unique($tids));
}在某种程度上,上面的解决方案的工作原理类似于term参数的深度属性和深度修饰符。
https://stackoverflow.com/questions/3293846
复制相似问题