Block visible for Specific Content Type but NOT Specific URLs
Developers and coders · Site administrators · Drupal 4.7.x · Drupal 5.x · Drupal 6.x · No known problems
Last modified: June 25, 2009 - 22:39
Here is a block visibility snippet for showing a block on certain content types but hiding it on specific URLs.
In this example you can see that this block is intended to be visible on Story and Page content types but invisible on the node edit and admin pages (specifically /edit* and /admin* URLs).
<?php
$match = FALSE;
// block is visible on the content types entered here
$types = array('story' => 1, 'page' => 1);
$url = request_uri();
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$node = node_load(arg(1));
$match = isset($types[$node->type]);
}
// block is invisible on URLs entered here
if (strpos($url, "edit")) {
$match = FALSE;
}
// copy paste these for additional URLs
if (strpos($url, "admin")) {
$match = FALSE;
}
return $match;
?>Also, You can see the alternative snippet which does sort of the opposite, which is show on content types and show on specific URLS.
Also, Drupal 7 will reintroduce a GUI for block visibility by content type, which reduces dependency on snippets like this one.
