Drupal Block Display by URL/URI Path & Content Type

The Drupal Block display system can be pretty limiting.  For a specific case, we needed to display a block based on both the url and the content type.  For example, we wanted to display the block on the blog overview page, and all blog pages.

Insert the following into your block page display tab with “Pages on which this PHP code returns TRUE (experts only)” selected…

<?php
$types = array(
  'blog',
  'news',
);
$uris = array(
  'blog', 
  'news',
  'archive/*',
);
$match = FALSE;
if ((arg(0) == 'node') && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $match = in_array($node->type,$types);
}
foreach ($uris as $uri){
  if(substr_count($uri,"*")){
    $uri = substr($uri,0,strpos($uri,"*")-1);
    $match |= (strpos(request_path(),$uri)===0);
  }else{
    $match |= (request_path()==$uri);
  }
}
return $match;
?>

In the “types” array, put the content types of any nodes where you want the block displayed.

In the “uris” array, put the uri of any paths where you would like the block displayed. You can use /* to include all sub paths.