Mark Royko + Associates

773-779-6301

Chicago Web Site Design

Our design process considers every aspect of your site, from easy navigation, to search engine optimization. Whether it's clean or ornamental, your site will look great and function perfectly.

Production

From online magazines to ecommerce, we can build you a site that is rock solid, easy to use and extremely affordable.

Web Site Maintenance and Service

At MR+A, we've got your back: After you're site is complete, we'll be there for service and support whenever you need us.

Topic “Theming”

Theme Taxonomy Terms As Links

Taxonomy terms in Drupal are usually displayed by printing out the $terms variable in the node template. This is great in most cases, but once in awhile you'll need to isolate one or two of these terms and output them as separate individual links, rather than as part of the main list.

(Take, for example, a case where you create a vocabulary based on story authors, making each author a term. This is a really useful way to organize archival content, but you probably don't want the author's name output on the same line as the story's other tags.)

There are several solutions to this puzzle. Spend some time looking at the suggestions found here —http://drupal.org/node/133223 — to see a few of them. If you don't have time to sift through all that try the following solution, which is adapted from code on the page just referenced.

One note: You'll need to know the vocabulary ID of the term you are referencing, so use Devel to find the taxonomy vocabulary id. Then add this function to your template.php file:

function your-theme-name_taxonomy_links($node, $vid) {
  if (count($node->taxonomy)){
     foreach ($node->taxonomy as $term) {
       if ($term->vid == $vid){
          $thelink = l($term->name, taxonomy_term_path($term));
          return $thelink;
          }
        }
    }
}

Now, just create a new node template file (of course, this should be specific to your content type, ie node-story.tpl.php), and add the following:

<?php print your-theme-name_taxonomy_links($node, $VID); ?> //$VID is the id of the vocabulary you want....

Of course, you'll need to remove the 'terms' variable, and probably output whatever remaining terms are left in a similar fashion, but that's a quick way to do it.

Syndicate content

Tune In. Sign On.

Sign up for the MR+A newsletter: Quarterly information on web development, design and optimization