For the life of me, I am unable to get contemplate to display my taxonomy term.

I can get it to print the whole path, for example: <?php print $node->path ?> works - returns the whole taxonomy path.

<?php print $node->taxonomy[9]->name ?> does not work - returns only the first node's taxonomy term.

Any ideas or help would be much appreciated.

Comments

clockwood’s picture

This seems to work for me:

foreach ((array)$taxonomy as $item) print $item->name

KG2’s picture

It works for me as well. What would I add to make it an active link?

Thanks in advance

KG2’s picture

<a href="?q=taxonomy/term/
<?php
foreach ((array)$taxonomy as $item) print $item->tid ?>">
<?php
foreach ((array)$taxonomy as $item) print $item->name
?>
</a>
lias’s picture

Here's another version I found from another post:

<?php foreach ((array)$taxonomy as $item) { ?>
<a href="<?php print base_path() . "taxonomy/term/" . $item->tid; ?>"><?php print $item->name ?></a>

But how do you add spaces?

felium’s picture

I am using this snippet to replicate how Drupal [ 6 ] writes out it taxonomy listing

<div class="terms terms-inline"><ul class="links inline">
  <?php foreach ((array)$taxonomy as $item) { ?>
   <li class="taxonomy_term_<?php print $item->tid; ?>"><a href="<?php print base_path() . "taxonomy/term/" . $item->tid; ?>" rel="tag" title=""><?php print $item->name ?></a></li>
  <?php } ?>
</ul></div>

Please note: Drupal also adds an extra class to the first and last list items [ 'first' and 'last' respectively ] which I haven't added to this example as I don't need them.