This is a how-to tip for Drupal 6, which I’m documenting because I couldn’t find this answer anywhere and it took me a day of scratching my head to figure it out. Drupalistas might find this useful, the rest of you can move along, there’s nothing for you to see here.
I was creating a View that listed all the nodes that have a given vocabulary term assigned to them, where the vocabulary term is passed in as the argument (e.g. http://mysite.myschool.edu/sitename/type/Basic ), where “type” is the path to the View, and “Basic” is the vocabulary term).
I wanted to include the description of the vocabulary term appear at the top of the View. How to do that?
The short answer is to put a short snippet of PHP code in the header of the View. Step by step:
- Make sure that the PHP filter module is enabled in the Core – optional section of Modules.
- Edit the Header item of your VIew (in the Basic Settings). If you’re using a WYSIWYG editor, make sure your input format is set to PHP Code.
- Paste this code into the Header box:
$term = taxonomy_get_term_by_name(arg(1));
- Update the View, then Save it. You won’t necessarily see the result in the Live Preview under the Views menus, but it should work in your site.
The slightly longer story here is that I think there’s a bug in the taxonomy_get_term_by_name() function that makes it so you have to reference $term->description instead of $term->description. I filed that bug on the Drupal.org site at http://drupal.org/node/812164.
Hope that helps other folks besides me – leave a comment if it works or doesn’t work for you.