Search code examples
drupal-theming

Drupal - Print content in node template if tagged with certain taxonomy term?


I want some content to only be printed in my node-type.tpl.php if the node has a certain taxonomy term.

With the following I can print the term's name if its ID is 5:

<?php print $node->taxonomy[5]->name ?>

Can I modify the code so it only prints something if the term ID is 5? I tried the following but it doesn't work:

<?php if ($node->taxonomy == '5'): ?> 
    Print something here if the term ID is 5.
<?php endif; ?>  

Im a bit of a newbie with advanced theming so I was hoping to not have to mess about with my template.php.

It seems more complicated than necessary but could the code from here be altered: Drupal - display blocks according to node's taxonomy term ID

Thanks


Solution

  • Got it working:

    <?php if ($node->taxonomy[5]): ?> 
        print stuff here
    <?php endif; ?>