Drupal主题:标签(Taxonomy Term)按类别显示

在Wordpress中,标签会按照类别显示。不过Wordpress就两种标签:文章分类和标签。在Drupal中,你可以创建不同类型的标签,如:文章分类,文章地点,涉及人物,天气等等类型(Vocabulary)。但是默认时会将这些标签(Taxonomy Terms)显示在一起,我们可以用下面的代码将这些标签按类别分开显示:


在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 .= ‘vid . ‘”>’ . $vocabulary->name . ‘: ‘;
foreach ($terms as $term) {
$links[] = ‘‘;
foreach($vocabularies as $vocabulary) {
if ($vocabularies) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid);
if ($terms) {
$links = array();
$output .= ‘

    vid . ‘”>’ . $vocabulary->name . ‘: ‘;
    foreach ($terms as $term) {
    $links[] = ‘ Posted on Categories Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *