Displaying a taxonomy term description at the top of a Drupal view

In Drupal, you can provide a description for each term in a taxonomy vocabulary. The default taxonomy term pages of Drupal 6 include the description at the top of each page (if only one term is present). Here's how you can achieve the same thing when using views.

  1. Make sure your theme has a page.tpl.php file. My theme is a subtheme of Zen so I copied the page.tpl.php file from the zen folder into my theme's folder.
  2. Create a duplicate of your theme's page.tpl.php file and call it page-taxonomy.tpl.php.
  3. Edit the new page-taxonomy.tpl.php file and add the following where you want the description to appear (for example at the end of the content-header):
    <?php if ($taxonomy_term_description): ?>
      <div id="taxonomy-term-description">
        <?php print $taxonomy_term_description; ?>
      </div>
    <?php endif; ?>
  4. Edit your theme's template.php file and add the following function:
    function yourtheme_preprocess_page(&$vars, $hook) {
      $term = taxonomy_get_term(arg(2));
      $vars['taxonomy_term_description'] = filter_xss_admin($term->description);
    }
    

After you clear your theme registry - by visting the admin/build/modules page - the term description will be displayed at the top of the page showing your taxonomy_term view.

Topic: 

15 Comments

Or just put this in the view

Or just put this in the view header (first enable the PHP filter module) :
<?php
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$tid = (int)arg(2);
$term = taxonomy_get_term($tid);
print (filter_xss_admin($term->description));
}
?>

Thanks a lot for this post!

Thanks a lot for this post! It' been very useful to me. Great!!!

I have another problem... maybe you could have the right solution: I have associated an image to each taxonomy term, using Taxonomy term module, but these images are not displaied in the view. Any idea to make them visible in the taxonomy term's associated views?

Thanks!