Drupal 6: PHP print based on two taxonomy terms
I am trying to use php to print something if the node has two specific terms开发者_如何学JAVA.
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';
}
}
?>
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';
}
精彩评论