By RichieRich on
Hi there,
I suspect that this may be a rather simple question, but despite Googleing I just can't seem to find the answer. I want to modify a node.tpl.php file based on taxonomy values. I understand that a list of taxonomy terms are sent as links, but I'd rather be able to get to the term id directly in order to do some logic.
Essentially I'd like to do something like this (pseudo-code)
if($terms contains $term)
{
- Add some php code here
}
Any suggestions? Is it best to go via the $node object?
Thanks in advance,
Richard
Comments
You can use $node->taxonomy
You can use $node->taxonomy which is the array of terms, so you can do something like
if ( !empty($node->taxonomy[{some_tid}]) ) {where {some_tid} is a numeric taxonomy term id (tid). Note that $node->taxonomy is not always set so if is good practice to make sure it's an array before using (if ( is_array($node->taxonomy) ) {).Thanks
Thanks nevets. Exactly what I needed. Just in case it's of help to anybody else my final code ended up like this (although the print messages are just for example):
Although this is nearly two
Although this is nearly two years old, I just want to say thanks to RichieRich for being generous enough to post the solution that worked for you. I had been researching this myself and didn't find the answer until I saw your post. Thanks again!