I’m just trying to restrict block visibility to nodes that have a certain taxonomy ID. I’m using this snippet…:
<?php
$term_id_to_trigger_show_block = 109;
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$terms = taxonomy_node_get_terms(arg(1));
foreach($terms as $term) {
if ($term->tid == $term_id_to_trigger_show_block) {
return TRUE;
}
}
}
?>
…but I get no joy, the block remains hidden on the relevant nodes.
Any ideas?
Cheers
It looks like in drupal6 taxonomy_node_get_tree() takes a node rather than a nid.
The easiest way to change your code is:
node_load() caches nodes in memory so it won’t be a big performance hit.
But wait! you may be able to refine this even further…
menu_get_item() will get the currently loaded menu item when the node object is loaded it will call taxonomy_node_get_terms(). So you can simplify to:
This will get other object types wich have a taxonomy object which could cause some confusion, if so stick the
arg(0) == 'node'back in.