node.tpl中词汇表的术语

时间:2010-08-10 19:15:02

标签: php drupal variables taxonomy

我在template.php中创建了一个变量,让我按词汇打印术语。问题是我希望能够传入一个词汇表id来选择一个特定的词汇表。我的代码如下所示:

function xnalaraart_classic_print_terms($node, $vocabularies){
    foreach($vocabularies as $vocabulary){
        if($terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid)){
            $output .= '<div>';
            $output .= '<ul class="links inline">';
            foreach ($terms as $term){
                $output .= '<li class="taxonomy_term_' . $term->tid . '">';
                $output .= l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
                $output .= '</li>';
            }
            $output .= '</ul>';
            $output .= '</div>';
        }
    }
    return $output;
}

并在preprocess_node函数中:

$vars['terms_split'] = xnalaraart_classic_print_terms($vars['node']);

如何编写它以便我可以将id传递给$词汇表?

1 个答案:

答案 0 :(得分:1)

我认为你让自己比实际上更困难。请参阅下面的最终功能。

function xnalaraart_classic_print_vocab_terms($node, $vid){
        if($terms = taxonomy_node_get_terms_by_vocabulary($node, $vid)){
            $output .= '<div>';
            $output .= '<ul class="links inline">';
            foreach ($terms as $term){
                $output .= '<li class="taxonomy_term_' . $term->tid . '">';
                $output .= l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
                $output .= '</li>';
            }
            $output .= '</ul>';
            $output .= '</div>';
        }
    return $output;
}

然后致电

$vars['terms_split'] = xnalaraart_classic_print_terms($vars['node'], 10);  //Where 10 is the vocab ID