By ac on
Hello,
I was wondering if anyone knew how to add the current taxonomy vocabulary to the node.tpl.php? I need any node under a vocabulary to display that vocabulary(no link is needed) in the node. I assume this is very simple but im still learning php and drupal.
thank you
Alex
Comments
bump. Im sure this is really
bump. Im sure this is really simple but if someone could help it would be greatly appreciated
vocab(s)
Don't forget that a node can have terms from multiple vocabularies. Based on a quick browse of the Drupal API, I don't think this is a one step problem unfortunately - corrections welcome from more experienced Drupal devs.
I'm just explaining how I'd go about figuring it out (I can't test any of this at the moment - sorry about the vagueness). Hopefully someone else could flesh it out with better code...
I notice node.tpl.php has a $taxonomy array (see http://drupal.org/node/11816). I'm not sure whether that is an array of ids, names or objects though. I have a horrible feeling it is already a themed list of links though.
If it is already a themed list of links, that approach probably wouldn't work that well, so going back a step I would start by getting an array of terms for that node via this function:
http://drupaldocs.org/api/4.6/function/taxonomy_node_get_terms
I would iterate through that array, and for each term I'd try to find out that terms vid from the term_data table. I'm not sure if there is an API function to do this directly without querying the database.
Here is an example function to get the vid (vocab id) from a tid (term id) - I pinched it from the taxonomy_context module:
Then once I had a vid, I'd get a vocabulary object using this function:
http://drupaldocs.org/api/4.6/function/taxonomy_get_vocabulary
From that vocabulary object, you could then get the name.
eg something like:
Sorry about all the vague guesswork, and not being sure of how much PHP you know - I've probably just dropped you straight in the deep end :)
Hey thanks. Good point about
Hey thanks. Good point about the multiple vocabs. I will take a look at that code, theres only one way to learn.
thank you
thank you.
Snippet that works with version 5
I got it working in version 5 and it's based on the taxonomy_link() function. Seems to work
Add taxonomy vocabulary to node.tpl.php
Hello ac.
I am searching for the same answer. I have a few new flexinode types. Each one is categorized in 2 or 3 taxonomies, some of them shared.
As an example, a certain "technology" (the new flexinode) is related to one or more topics (agriculture, alternative energies, etc.), and one or more regions.
Now, al the topics and regiones appear together, but I would like them to show like:
Topics: topic A, topic E
Regions: region A, region C
Is this what you are searching for? I am sure that this scenario is common to many drupal installations.
Unfortunately, I am no coder nor do I know PHP... :-(
I hope you can find a solution for this. If my xhtml and css knowledge are useful, just drop me a note and I will be more that glad to help. :-)
Regards...
--
Eduardo Mercovich
Buenos Aires, Argentina
Vocabulary and Term Listings
Eduardo and AC,
Any answer yet? I'm looking to do the same thing and am not the best with PHP just yet.
I too am looking for a way to list both the vocabulary name, followed by a list of terms associated with a node.
I think this would be very useful, especially if the similar taxonomy term names appear in different vocabularies.
-sean
Sean Larkin
This might help
This isn't exactly what you are looking for, however, it might help. Basically, I needed to get the links/list of terms within individual vocabularies. Put the following into your theme's template.php file:
... and then place something like this in the node.tpl.php or flexinode equivalent:
This would print the links for all of the terms for vocabulary 1. Just change the number for other vocabularies.
This doesn't exactly address what you are looking for, however, I hope it helps.
Thanks Eric
It works just great Eric. :-)
Thanks a lot for your help. If someone happens to be in this same spot, I didn't had a template.php (I am yet using the default themes, so I created one that had only this code (just copy and paste into a template.php file and you are done).
Again, thanks for sharing your knowledge. :-)
Best regards...
--
Eduardo Mercovich
Buenos Aires, Argentina
Subscribing, looking for
Subscribing, looking for code to pinpoint the exact term in a vocabulary also on node.tpl.php,
greetings, Martijn
may be This artical can help you
http://dolphinibiz.com/custom-node-tpl-according-to-menu