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

时间:2011-01-11 21:29:07

标签: php drupal drupal-6 taxonomy

如果节点有两个特定的术语,我试图用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';
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

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';
}