[英]Drupal: Views - Print taxonomy term description in header
我正在使用以下代码在视图页面标题中打印分类术语。
<?php
$view = views_get_current_view();
$term_name = array_pop($view->args);
$term_name = str_replace('-', ' ', $term_name);
$possible_terms = taxonomy_get_term_by_name($term_name);
$term = $possible_terms[0];
print '<div class="term-desc">';
print filter_xss_admin($term->description);
print '</div>';
?>
我遇到的问题是,它适用于具有多个单词的所有术语,但是在术语名称仅包含一个单词的术语上,它不会打印说明。
尝试
$term = array_pop($possible_terms)
代替
$possible_terms[0].
您也可以尝试执行
foreach($possible_terms as $key=>$term){
$desc = $term->description
}
如果这样做没有帮助,请执行var_dump($ possible_terms);。 查看您的数据结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.