Drupal:Views - 在标题中打印分类术语描述

时间:2011-04-08 17:38:26

标签: php drupal drupal-views taxonomy

我使用以下代码在视图页面标题中打印分类术语。

<?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>';
?>

我遇到的问题是,它适用于包含多个单词的所有术语,但对于术语名称只有一个单词的术语,它不会打印说明。

1 个答案:

答案 0 :(得分:1)

尝试

$term = array_pop($possible_terms) 

而不是

$possible_terms[0]. 

您也可以尝试

foreach($possible_terms as $key=>$term){
  $desc = $term->description
}

如果这样做没有帮助     后续代码var_dump($ possible_terms);  查看您的数据结构。