By cwebster on
I modified this little piece of code and thought it might come in handy for someone. Basically, when you have a block that you would like to show only for a certain content type, or a "subfolder" of the current alias, you can use this code.
Just go to "admin/build/block/configure/[block-name]", under "Page specific visibility settings", choose "Show if the following PHP code returns TRUE (PHP-mode, experts only).", and paste the following code into the text area. You'll need to set the node type(s) and the subfolder to whatever your current situation requires, as well. Good luck!
<?php
// CHECK NODE TYPE
// List the allowed node types in an array.
$allowed_node_types = array(
'exss_page',
'attr_page',
);
// Check the Drupal path to get the NID for the current node.
if(arg(0) == 'node' && is_numeric(arg(1))) {
// Store the current node's information in the $node array.
$node = node_load(arg(1));
// If the current node's $node->type is in the $allowed_node_types array, return TRUE.
if(in_array($node->type,$allowed_node_types)) {
return TRUE;
}
}
// CHECK AN ALIAS "SUBFOLDER"
// Split up the requested URI by folders (similar to arg())
$req = explode('/',request_uri());
// If the subfolder (second place) of the requested URL equals "exss", return TRUE.
if($req[1]=='exss'){
return TRUE;
}
?>