node.tpl 中的词汇术语

发布于 2024-09-13 22:20:22 字数 1007 浏览 12 评论 0原文

我在 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 传递给 $vocabularies?

I've created a variable in template.php that let's me print terms by vocabulary. The problem is that I want to be able to pass in a vocabulary id to select a specific vocabulary. My code looks like this:

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;
}

and in the preprocess_node function:

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

How do I write it so that I can pass in an id to $vocabularies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

書生途 2024-09-20 22:20:22

我认为你让自己变得比实际情况更困难。最终功能见下文。

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

I think you made this more difficult on yourself than it really is. See below for final function.

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;
}

And then call

$vars['terms_split'] = xnalaraart_classic_print_terms($vars['node'], 10);  //Where 10 is the vocab ID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文