I would like to change the tpl.php file used depending on the taxonomy term applied to a node.
There is a snippet on this page that explains how to do that. However, it is written for Drupal 6, and doesn't work for Drupal 7.
The snippet is as follows:
// Add this to your theme's template.php
// Replace "THEMENAME" with your theme's name
function THEMENAME_preprocess_node(&$vars) {
foreach ($vars['node']->taxonomy as $term) {
$vars['template_files'][] = 'node-term-'. $term->tid;
}
}
I have tried to update it for Drupal 7 as follows:
function THEMENAME_preprocess_node(&$variables) {
foreach ($variables['node']->taxonomy as $term) {
$variables['template_files'][] = 'node-term-'. $term->tid;
}
}
However, it still doesn't work. I just get the following error message:
Notice: Undefined property: stdClass::$taxonomy in THEMENAME_preprocess_node() Warning: Invalid argument supplied for foreach() in THEMENAME_preprocess_node()
Any help would be appreciated.