By scalp on
I want to show a block only on two node type pages. I don't want it to show on their node/add pages. I found this, but it doesn't seem to work:
$match = FALSE;
$types = array('interest' => 1, 'comment' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}
return $match;
?>
Can anyone help me figure out why it's not working? Thank you.
Comments
...
See this page, where you'll find a block of PHP visibility code titled "Show block only for specific content type". Have no idea what you're trying to do with:
Found it
Thank you for the quick reply. I found this in the handbook: http://drupal.org/node/60317. Very helpful links for all sorts of snippets relating to block visibility. It didn't turn up in my original search when I posted earlier. The line that you're questioning though, comes right from the link that you sent. If you look at the snippet that is for "Show block only for specific content type:". I just changed the content types to fit my situation.
The snippet implies you have
The snippet implies you have content types with the machine readable name set to 'interest' and 'comment' ('Type' column on admin/content/types). Is this correct?
Also, it is better to write the call to node_load as
since such calls are cached avoiding another call to the database to load the node.
Also the snippet is missing the opening
<?phpwhich may be just a cut and paste error.this also works
if ($node = menu_get_object()) {
return($node->type=='agent' || $node->type=='exhibition')
}
--
keine zeit für spielkonsolen mein leben ist jump n run!
valderama.net