canintex
canintex

Reputation: 638

Drupal: Views - Print taxonomy term description in header

I am using the following code to print the taxonomy term in the views page header.

<?php
$view = views_get_current_view();
$term_name = array_pop($view->args);
$term_name = str_replace('-', ' ', $term_name);
$possible_terms = taxonomy_get_term_by_name($term_name);
$term = $possible_terms[0];
print '<div class="term-desc">';
print filter_xss_admin($term->description);
print '</div>';
?>

The issue I'm having is that it works with all of the terms that have more than one word, but on the terms with only one word for the term name, it won't print the description.

Upvotes: 0

Views: 1419

Answers (1)

Joseph.Chambers
Joseph.Chambers

Reputation: 11

Try

$term = array_pop($possible_terms) 

instead of

$possible_terms[0]. 

You can also try doing a

foreach($possible_terms as $key=>$term){
  $desc = $term->description
}

If that doesn't help do a var_dump($possible_terms); to see your data structure.

Upvotes: 1

Related Questions