2010-07-20 95 views
0

我一直在努力將節點術語的父術語id放在視圖參數中。讓我解釋一下我爲什麼要做這樣一件奇怪的事情。那麼,在術語頁面上,我展示了一個包含該術語下所有節點列表的塊。但是,當點擊任何節點時,該塊將作爲缺省參數(對於術語ID)在視圖中消失爲: if(arg(0)=='taxonomy'& & arg(2)!=''){ return arg(2); } 這是用於分類安排,如團隊>>國家>>澳大利亞>>特點,文章等 這裏:詞彙是團隊:國家是主要術語,澳大利亞是兒童術語和特徵,文章等是兒童的子女術語 沒關係。但是由於我想在該節點的節點頁面上顯示Block,所以我想拉該節點的術語的父項'ID [因爲節點是(例如)特徵下的文章,我顯示的節點列表的塊是在澳大利亞],以便我可以添加更多參數,如: elseif(arg(0)=='node'){ 然後...... Plz幫助。Drupal 6-節點的父項術語ID

回答

2

如果我正確地理解了這個問題,您希望顯示一個塊,該塊顯示與節點術語的直接父節點具有相同分類術語的所有節點。 如果節點有2個項a> b(即a是b的父項),則該項爲a。 如果你有一個> b> c並且所有的都已經設置好了,那麼你就有一個和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)); 
} 

在某種程度上,在溶液上方的工作方式類似於深度屬性和深度改性劑的術語參數。