====== Drupal Taxonomy ====== ===== Drupal Taxonomy 按类别显示 ===== 在Wordpress中,标签会按照类别显示。不过Wordpress就两种标签:文章分类和标签。 在Drupal中,你可以创建不同类型的标签,如:文章分类,文章地点,涉及人物,天气等等类型(Vocabulary)。但是默认时会将这些标签(Taxonomy Terms)显示在一起,我们可以用下面的代码将这些标签按类别分开显示: ==== 第一步,定义显示标签的函数 ==== '; //checks to see if you want an ordered list if ($vid) { //checks to see if you've passed a number with vid, prints just that vid $output = '
'; foreach($vocabularies as $vocabulary) { if ($vocabulary->vid == $vid) { $terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid); if ($terms) { $links = array(); $output .= ''; if ($ordered_list) $output .= '
  • ' . $vocabulary->name . ': '; foreach ($terms as $term) { $links[] = '' . l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description))) .''; } $output .= implode(', ', $links); if ($ordered_list) $output .= '
  • '; $output .= '
    '; } } } } else { $output = '
    '; foreach($vocabularies as $vocabulary) { if ($vocabularies) { $terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid); if ($terms) { $links = array(); $output .= '
      '; if ($ordered_list) $output .= '
    • ' . $vocabulary->name . ': '; foreach ($terms as $term) { $links[] = '' . l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description))) .''; } $output .= implode(', ', $links); if ($ordered_list) $output .= '
    • '; $output .= '
    '; } } } } if ($ordered_list) $output .= ''; $output .= '
    '; return $output; } ?>
    ==== 更新主题模板文件 ==== ==== 参考文件 ==== * http://drupal.org/node/133223