there are a lot of useful functions included as part of the taxonomy module and the taxonomy_context module. these would allow me to gather and display some contextual information for any of my nodes. the problem is i haven't found a way to pass either the node's tid or vid as a parameter to these functions.

is there a way to get the current node's tid or vid? and once gathered, how would i pass that info to the function?

thanks a bunch for your help. this info will really help me jumpstart my first drupal site.

Comments

frjo’s picture

Where is it you want to get the current node's tid or vid? A PHPTemplate theme, some module, a block?

Include som code examples and it will be easier to give advice.

masande’s picture

Actually I am trying to get the TID and VID when I display a node. Definitely not from a module or a block, however. I've been using the following hacked code to get the current node's TID so I can pass it to various functions for output:

$terms = taxonomy_node_get_terms($node->nid);
$termlist = array();
foreach ($terms as $key => $tobj) { // $key is the TID for the displayed node.
  $termlist[] = $tobj->name;
}
$fancyterm = theme_item_list($termlist);

Since all of my nodes only belong to a single term I only get a single TID returned from the previous technique.

Is there a shorter ad more direct to get this info?

Thanks again for the help.

Mark Sanders
Q Collective

frjo’s picture

function _phptemplate_variables($hook, $vars) {
  switch($hook) {
    case 'node':
      if (module_exist('taxonomy')) {
        $termlist = array();
        foreach (taxonomy_node_get_terms($vars['node']->nid) as $term) {
          $termlist[] = $term->name;
        }
      }
      if (count($termlist)) {
        $vars['fancyterm'] = theme_item_list($termlist);
      }
      break;
  }

  return $vars;
}
ryanrain’s picture

i pasted this function in my template.php but it completely broke my theme. i'm running a phptemplate theme in 5.3. has it worked for anyone else?

i'm also trying to get a node's term id, and have explained this in more detail in another post http://drupal.org/node/191111

guess i'll keep lookin.
peace.
-r

giorgio79’s picture