I was wondering if anyone could help me to find/write the php code to call the description for a taxonomy term on it's page? I have built a custom page using views to display the term, and would like to put php code into the header to display the term description, but my skills in coding are lacking. Please help!

Comments

pixelite’s picture

There's a solution posted here that should work: http://drupal.org/node/276341.

traceelements’s picture

Pixelite, that worked! I changed part of the code (taxonomy_get_term replaced with taxonomy_term_load) to work for Drupal 7. Here's what I used in case anyone else has this issue:

<?php $current = taxonomy_term_load(arg(2)); ?>
<?php if ($current): ?>
    <div class="taxonomy-description">
        <?php echo $current->description; ?>
    </div>
<?php endif; ?>
nelslynn’s picture

Does anyone know how to apply this to the taxonomy/term/all page (for Drupal 7)? I'd like to accomplish output like this:

Taxonomy Term Title
Taxonomy Term Description (this is the kicker... how can I output the Description associated with the term, and repeat for each term on the SAME page... urgggg)
Node teasers related to the term

Taxonomy Term Title
Taxonomy Term Description
Node teasers related to the term

Taxonomy Term Title
Taxonomy Term Description
Node teasers related to the term
etc

Urgg this is so frusting to figure out, yet is should be a simple setting.

Thanks for anyone's help.

softprayog’s picture

One has to add this code in the page.tpl.php template file, just above the line, print render($page['content']);. It works like magic.

brandonbyers’s picture

The code above gives me an empty result (I'm running Drupal 7). I placed
this into page--front.tpl.php ...

<?php $current = taxonomy_term_load(arg(2)); ?>
<?php if ($current): ?>
    <div class="taxonomy-description">
<?php echo $current->description; ?>
    </div>
<?php endif; ?>

... and I changed the 2 to various numbers, and every time it just comes up empty. On a related note, is it true that I can see the term-id by studying the URL when I edit the term?

Please advise.

rsrocha’s picture

On a related note, is it true that I can see the term-id by studying the URL when I edit the term?

Yes, it will appear something like: yoursite/taxonomy/term/7/edit/destination/admin/structure/taxonomy/vocabularyname . The term-id is the number 7 after taxonomy/term
( dont want to be rude, but you could have tried it urself instead of asking )

For the rest of ur answer, if u are trying to read all the terms and create a div for each one, you could do something like this:

<?php
$vid = taxonomy_vocabulary_machine_name_load("YourVocabularyMachineName")->vid;
$terms = taxonomy_get_tree($vid, 0, null, true);
$term_count = count($terms);
					
for ($i = 0; $i < $term_count; $i++) {
//dont need to have the next tree lines, i used it to not repeat myself - this is just a piece of code from my website
$name = $terms[$i]->name; 
$id = $terms[$i]->tid;
$description = $terms[$i]->description;
?>
<div id="<?php print $id; ?>" class="taxonomy-description">
<?php print $description; ?>
 </div>
<?php } ?>

Note that this will print all the terms available in the vocabulary that u inserted in the variable $vid. So if u have 8terms, it will print 8 divs - each one with their respective term's description.

Hope that this is what u want :)

msamavi’s picture

Dear rsrocha, can you advise how I can use your block code to display only the description of the term selected in a node creation form page?