Pedro Posada | Block visibility php snippets

Block visibility php snippets

Posted on May 26, 2008 - 10:19am
<< 29 of 46 >>

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;

?>

Post new comment

The content of this field is kept private and will not be shown publicly.
Please solve the math question. This way we will know you are not a robot.