By esllou on
I've tried everything to get the tid of a taxonomy term in a node-nodeprofile.tpl.php template.
Using ConTemplate, I've found:
print $node->taxonomy[520]->tid
but that's not much use if I don't know the tid to start with.
print $node->taxonomy->tid
produces nothing at all.
I only have one vocabulary (vid 13) being used on nodeprofiles. I thought it would be quite a basic bit of php but haven't been able to find anything on drupal.org.
Comments
Sorry just an ID or names of
Sorry just an ID number or names of the term ID?
If names, then try this.
1. Place this function in your template.php:
2. Call from your .tpl:
where 13 is your vid
It's actually somewhere in google, but I forgot the link, sorry. Just try googling around for more info.
love, light n laughter
blogid.net
love, light n laughter
it was just the tid I needed
it was just the tid I needed as I need to use it in a link to a View.
Why not just use the
Why not just use the taxonomy_node_get_terms_by_vocabulary() function?
http://api.drupal.org/api/function/taxonomy_node_get_terms_by_vocabulary/5
Just do something like this
$term = taxonomy_node_get_terms_by_vocabulary($node->nid, {your vid})
The function returns an object, so you have to extract the tid from it.
$tid = $term->tid;
echo arg(2);
echo arg(2);
My Drupal sites:
Easier Solution?
I've tried
echo end($node->taxonomy)->tid; //Works if you have only one tid per node, so that end and first are the same
or
reset($node->taxonomy);
$k = key($node->taxonomy);
echo $node->taxonomy[$k]->tid;
--
Massimo - http://impronta48.it
easy way
Put this in your node.tpl.php
or take a look here: http://drupal.org/node/44938
Sasha
Print & Screen