By cajun67 on
I've set up Drupal 6 so that the user can choose a custom header jpg on the page by choosing the taxonomy term. I think I've got the right code, but it's not working:
$node = node_load($nid);
$terms = taxonomy_node_get_terms_by_vocabulary($node,0);
$header_term=$terms[0]->name;
switch($header_term)
{
case 'header 2' :
$header_pic="header2.jpg";
break;
case 'header 3' :
$header_pic="header3.jpg";
break;
default :
$header_pic="header1.jpg";
break;
}Not working. I've tried $print_r($header_term) in the page to see what I'm getting, and it outputs a blank array.
Comments
Since the second argument to
Since the second argument to taxonomy_node_get_terms_by_vocabulary is a vocabulary id and 0 is not a valid vocabulary id that is likely the source of your problem. You also do not show where $nid comes from, but if this is in page.tpl.php $node will be defined already when viewing a single node (unaliased path of the form node/{nid}). $node is also defined in node.tpl.php.
You may also want to investigate the taxonomy image module.