Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

How do i get all the taxonomies of a node to render in Drupal7?

Olivia Rhye

After following a tutorial for getting the taxonomy terms of a node, I found that I still didn't have all the pieces of the puzzle. Doing a foreach over $tags = $node->field_tags; would just give a disappointing one result with those nodes had more than one taxonomy assigned to it. (The other 3 were being lost in the code abyss!)

This was solved by digging a little deeper into the object that was return:

<div class="tagsList views-field-field-tags">
<? $tags = $node->field_tags['und']; ?>
Tags: <? $count = 0;
foreach($tags as $tag){
if($count > 0){echo ", ";}
echo '<a href="'.taxonomy_term_path($tag['taxonomy_term']).'">'.$tag['taxonomy_term']->name.'</a>';
$count++;
} ?>
</div>

Turns out i had to go one layer deeper to loop the tags object as the language code is undefined. SO now my taxonomies are working great on the node.tpl.php for that feed.

Source

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy