Return to Snippet

Revision: 20647
at November 20, 2009 13:22 by zachharkey


Initial Code
Add the following preprocess function to your theme template.php. If you already have this function, then just add the highlighted line. 

function genesis_custom_preprocess_node(&$vars, $hook) {
  $vars['terms_split'] = genesis_custom_split_terms($vars['node']);
}

// Add the following function to the bottom of your theme template.php
// Split out taxonomy terms by vocabulary
function genesis_custom_split_terms($node) {
  $vocabularies = taxonomy_get_vocabularies();
  foreach($vocabularies as $vocabulary) {
    $terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocabulary->vid);
    if ($terms) {
      $links = array();
      foreach ($terms as $term) {
        $links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
      }
      $items[] = '<span class="label">'. $vocabulary->name .'</span>' . '<span class="sep">:</span> '. implode('<span class="glue">,</span> ', $links);
    }
  }
  return theme('item_list', $items, NULL, 'ul');
}

// Finally, in your node.tpl.php add the following line wherever you want the new split terms:

<?php print $split_terms ?>

Initial URL

                                

Initial Description
These instructions were written for a genesis subtheme but should work for any theme.

Initial Title
Display Drupal taxonomy terms grouped by vocabulary

Initial Tags

                                

Initial Language
XHTML