Drupal 6:基于两个分类术语的 PHP 打印

发布于 2024-10-11 20:03:26 字数 328 浏览 5 评论 0原文

如果节点有两个特定术语,我尝试使用 php 打印一些内容。

像这样的东西:

<?php
    $terms = taxonomy_node_get_terms($node, $key = 'tid');
    foreach ($terms as $term) {
        if ($term->tid == 19) {
            print '19';
        }
        if ($term->tid == 21) {
            print '21';
        }
    }
?>

I am trying to use php to print something if the node has two specific terms.

Something like:

<?php
    $terms = taxonomy_node_get_terms($node, $key = 'tid');
    foreach ($terms as $term) {
        if ($term->tid == 19) {
            print '19';
        }
        if ($term->tid == 21) {
            print '21';
        }
    }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

权谋诡计 2024-10-18 20:03:26

taxonomy_node_get_terms() 返回一个数组,其中术语 ID 作为数组键。因此,要做类似您想要的逻辑的事情,您需要类似以下的内容:

$tids = taxonomy_node_get_terms($node); 
// a $node object is passed as the only parameter in this case, so you would need to use node_load to get that
// the function has an optional second parameter, and 'tid' is the default, so it's not needed
$tids = array_keys($tids);
if (in_array(19, $tids)) {
  print '19';
}
if (in_array(21, $tids)) {
  print '21';
}

taxonomy_node_get_terms() returns an array with the term IDs as the array key. So to do something like the logic you're wanting, you'd need something like the following:

$tids = taxonomy_node_get_terms($node); 
// a $node object is passed as the only parameter in this case, so you would need to use node_load to get that
// the function has an optional second parameter, and 'tid' is the default, so it's not needed
$tids = array_keys($tids);
if (in_array(19, $tids)) {
  print '19';
}
if (in_array(21, $tids)) {
  print '21';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文