background image

Content tagged with: term

Eric's picture

If someone clicks on a taxonomy term they land on a page showing all the content tagged with that term. The title on those pages is simply the taxonomy term. I thought it would be more usable if I changed the verbiage of the title to let the user know what they are viewing. This code snippet shows how you can change the title for the taxonomy term landing pages:

<?php
function MYTHEME_preprocess_page(&$variables) {
  if (
arg(0)=='taxonomy' && arg(1)=='term') {
   
$variables['title'] = "Content tagged with: " . $variables['title'];
  }
}
?>

Eric'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>";
?>