Drupal - Taxonomy Description in View

in

Q: How do I arrange for the taxonomy term description text to be displayed when I use the built in 'taxonomy_term' view to handle the display of my taxonomy lists?

A: You can get the text to display by enabling the view's header and adding in some PHP code which queries and displays the text...

The 'taxonomy_term' view is a fantastic alternative to drupal's built in taxonomy display mechanism. You can use it to customise the living daylights out of your taxonomy display, especially if you use it in conjunction with modules like Taxonomy Image. We have used it a lot recently on our web sites when the web design calls for displaying grids of products with product pictures and the like.

Anyway, the view has one small problem in that it doesn't display the taxonomy term's description text at the top of the page in the way that the default taxonomy display method does.

After some searching we found a way to easily get the view to display the description text here (see the comment on Nov. 2008 by Guix):

http://www.norio.be/blog/2008/10/displaying-taxonomy-term-description-to...

Here are the steps we used:

(1) Enable the view's Header

(2) Set the header's input format to PHP

(3) Paste in Guix's PHP code:

<?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));
}
?>

This code gets the taxonomy term id from the url, uses it to load the corresponding taxonomy term and then pulls out and prints the term description text.

(4) Press Update & Save View

Now when the view is displayed it should insert the taxonomy description txt at the top.

It worked really well for us and we're very grateful to Guix for the tip - cheers, it really helped us out!

Stranger
Stranger's picture
Thanks

This Worked great, Only I am still not sure why I could not do this with a page attachment, it seems simple enough but If I did this, it kept on showing all the taxonomies related to the nodes that were showing!

I thought I knew views, apparently I still have a way to go!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Pride on FacebookPride on TwitterPride on TwitterPride on Twitter

Join Our Newsletter

* indicates required

Irish Internet Association

finalist.png
phone-number.png