background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
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>";
?>

Eric.London's picture

Here's a quick snippet to add the current page to the breadcrumbs. I added this code to my template.php file.

<?php
function MYTHEME_breadcrumb($breadcrumb) {
  if (!empty(
$breadcrumb)) {
   
// add current page
   
$breadcrumb[] = l(drupal_get_title(), $_REQUEST['q']);
    return
'<div class="breadcrumb">'. implode(' ยป ', $breadcrumb) .'</div>';
  }
}
?>

Eric.London's picture

Here is how you can generate the html from a view and embed into a page callback or node.

<?php
function MYMODULE_MYFUNCTION() {
 
// ...code...
  // define view name
 
$viewName = 'MY_VIEW';

 
// get the view object
 
$view = views_get_view($viewName);
   
 
// create an array of arguments
  // NOTE: if you are using arguments, you can pass them into this function
 
$viewArgs = array();

 
// create view html
 
$viewHtml = views_build_view('block', $view, $viewArgs, FALSE, $view->nodes_per_block);
   
  if (
$viewHtml) {
   
$page_contents .= "<h3>" . $view->block_title . "</h3>";
   
$page_contents .= $viewHtml;
  }
 
// ...code...
}
?>

In this example, I am using a block view. You can also use a page or embedded layout and adjust as necessary. I find it helpful to show the contents of the view object to see what's available to you. For instance...

<?php
echo "<pre>" . print_r($view, TRUE) . "</pre>";
?>

Syndicate content