Community

Select custom node template when taxonomy term is present.

I'm pretty sure this has been discussed somewhere but I haven't found it. I'm trying to select a custom node template for a particular type of content ONLY when a particular taxonomy term is present. My new templated is called node--custom1.tpl.php. It should be used only when an "eventdate" type node includes the taxonomy term with tid=44. I've had no trouble editing the the template.php file and causing the new template to be used for all eventdate nodes, but tried various approached and haven't succeeded in limiting the change only to nodes with the required taxonomy term. I know I need something like this in the template.php file:

function MyTheme_preprocess_node(&$variables) {
  $node = $variables['node'];
  if($node->type == 'eventdate') {

// something here to check for taxonomy->tid=44;
//    which I think requires $terms = field_view_field('node', $node, 'field_tags');
// and maybe somthink like foreach($terms AS $tax_term){
// if($tax_term->tid==44){
$variables['theme_hook_suggestions'][] = 'node__' . 'custom1';
         }
     }
  }
}

but nothing has worked. Any guidance is appreciated.

Comments

Make the template name as

Make the template name as "node--custom1.tpl.php"

sorry, that was a typo

The template is named correctly (node--custom1.tpl.php) and is selected correctly, until I try to include a check for the the correct tid. That's the part where I seem to be misunderstanding something.

corrected

The typo is corrected in my original posting

nobody click here