background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount

Displaying the taxonomy term description

Eric.London's picture

When using views to handle the taxonomy term pages, you may not have the taxonomy term description available in your page variable scope (either page.tpl.php or page-taxonomy.tpl.php). If you'd like to display it at the top of the page, you can add a preprocess function in your theme to add the variable:

<?php
function MYTHEME_preprocess_page(&$variables) {
 
// check to see if this is a taxonomy term page
 
if (arg(0)=='taxonomy' && arg(1)=='term') {
   
// load the taxonomy term object
   
$term = taxonomy_get_term(arg(2));

   
// add the taxonomy term description to the variables
   
$variables['taxonomy_term_description'] = $term->description;
  }   
}
?>

Now in your page.tpl.php (or page-taxonomy.tpl.php) file, you can add the following line of PHP to output the description. NOTE: I enclosed it in a div with a class so I can add necessary CSS easily.

<?php
if ($taxonomy_term_description) print "<div class='taxonomy_term_description'>$taxonomy_term_description</div>";
?>

Thank you for this. I was

Thank you for this. I was trying to get a term name into an RSS link title attribute and even though it's not directly related to you post, it helped me visualize and understand extracting what I wanted from the object ($term->name).

I do this to generate a RSS feed on a taxonomy term page through Panels:

<?php
  $objects
= taxonomy_get_term(arg(2));
 
drupal_add_feed(url('taxonomy/term/' . arg(2) . '/0/feed'), 'RSS Feed for ' . $objects->name);
?>