Drupal - 如果使用特定的分类术语标记,则在节点模板中打印内容?

时间:2011-04-08 13:02:38

标签: drupal-theming

如果节点具有特定的分类术语,我希望只在我的node-type.tpl.php中打印一些内容。

如果ID为5,则可以打印该术语的名称:

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

我是否可以修改代码,以便只有在ID为5的情况下才会输出内容?我尝试了以下但是它不起作用:

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

我是一个有高级主题的新手,所以我希望不必乱用我的template.php。

似乎比必要的更复杂但是可以改变这里的代码: Drupal - display blocks according to node's taxonomy term ID

谢谢

1 个答案:

答案 0 :(得分:1)

搞定了:

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