如果分类术语之一是“绿色”,则显示文本片段?
我希望能够根据节点是否标记有特定的分类术语来显示或隐藏节点上的文本片段。
大致如下:
if (term('green')) {
echo"this is green";
}
else {
echo "not green";
}
Drupal 执行此操作的方式是什么?
I want to be able to show or hide a text snippet on a node based on whether or not it was tagged with a specific taxonomy term.
Something along the lines of:
if (term('green')) {
echo"this is green";
}
else {
echo "not green";
}
What is the Drupal way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您在 node.tpl.php 内部工作,并且您心中有一个非常具体的术语:
您可以从节点内部访问
$taxonomy->taxonomy_term_YourTermID
.tpl.php 文件,并基于该文件进行测试。如果您想要更抽象的解决方案,我建议您安装 devel 模块,并根据相关节点中“Devel”选项卡下显示的内容在
template.php
文件中构建一个函数。Assuming from your example that you're working from inside of node.tpl.php, and that you have a single very specific term in mind:
You can access
$taxonomy->taxonomy_term_YourTermID
from within your node.tpl.php file, and test based on that.If you'd like a more abstract solution, I'd recommend installing the devel module and building a function in your
template.php
files based on what shows up under the 'Devel' tab in the relevant node.