如果分类术语之一是“绿色”,则显示文本片段?

发布于 2024-09-16 00:54:49 字数 187 浏览 14 评论 0原文

我希望能够根据节点是否标记有特定的分类术语来显示或隐藏节点上的文本片段。

大致如下:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋葬我深情 2024-09-23 00:54:49

假设您在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文