0

I am trying to print taxonomy terms using this code:

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

It works fine if I put in contemplate, however it doesn't in the full node (node.tpl.php), the tags are empty in the full node. Can any one tell me what is the reason for this and how to fix this?

3
  • Are you sure the $taxonomy variable is populated in node.tpl.php of your theme?
    – SMTF
    Jun 11, 2012 at 21:03
  • No, how can I do this?
    – Vonder
    Jun 11, 2012 at 21:04
  • Place this: <h1> value of tax var is: <?php print print_r($taxonomy, TRUE); ?> </h1> In your node.tpl.php page. That is prob. the easiest way. Unless you have Devel module installed, if so just use <?php dsm($taxonomy); ?> in the template instead.
    – SMTF
    Jun 11, 2012 at 21:05

1 Answer 1

2

First verify that the $taxonomy variable is available and populated in your node.tpl.php file. ...

EDIT:

Your accessing the values in your $item variable like it is an object but your casting to an array. Try accessing as an array:

 <a href="<?php print base_path() . "taxonomy/term/" . $item['tid']; ?> "class='tags'><?php print $item['name'] ?>,</a>
3
  • OK, the variable is available, however still it is not printed..
    – Vonder
    Jun 11, 2012 at 21:57
  • Nothing..It seems liek some declaration is missing as the code works correctly when (if teaser) but doesnt work wjen (if full node)...
    – Vonder
    Jun 12, 2012 at 14:59
  • @Vafello Wait. Can you post the results of the dsm print of the $taxonomy variable? It may be that you have to specify which Vocabulary you want printed.
    – SMTF
    Jun 13, 2012 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.