Drupal Separate Taxonomy Terms

Posted under » Drupal on 25 July 2011

This applies to Drupal 6

Most Drupal templates do not separate the taxonomy terms by vocabulary except a few like the Wabi theme. There is another approach shared by Tim "TimOnWeb" Kamanin, if you google for it.

As usual, edit the template.php by adding this function.

function garland_separate_terms($node_taxonomy) {
if ($node_taxonomy) {
//separating terms by vocabularies
foreach ($node_taxonomy AS $term) {
     $links[$term->vid]['taxonomy_term_'. $term->tid] = array(
           'title' => $term->name,
           'href' => taxonomy_term_path($term),
           'attributes' => array(
                         'rel' => 'tag',
                         'title' => strip_tags($term->description)
                         ),
         );
                     }
//theming terms out
foreach ($links AS $key => $vid) {
   $terms[$key] = theme_links($vid);
                                 }
                                                 }
return $terms;
}

What this does is to convert the terms into array.

Now go to node.tpl.php file and in the beginning of the file write the following:

$terms = garland_separate_terms($node->taxonomy); 

(Note: Change Garland to your theme name). Now replace old Drupal print $terms; with

1st category: <¿php print $terms[1]; ?>
2nd category: <¿php print $terms[2]; ?>

Where [?] is the vocab id.

See also earlier theming post.

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css