Block visibility php snippets
Block visibility php snippets
Categories:Display a block on certain pages by url and by node type.
<?php
$match = FALSE;
$types = array('content_type_one' => 1, 'content_type_two' => 2);
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;
}
}
$desired_paths = array('page1', 'page2');
if ($_GET['q']) {
$my_drupal_path = $_GET['q'];
} else {
$my_drupal_path = substr($_SERVER['REQUEST_URI'], 1);
}
$my_path_alias = drupal_get_path_alias($my_drupal_path);
foreach ($desired_paths as $desired_path) {
if (stristr($my_path_alias, $desired_path)) {
$match = TRUE;
}
}
return $match;
?>- 1092 reads
Post new comment