Pedro Posada | Block visibility php snippets

Block visibility php snippets

Posted on May 26, 2008 - 10:19am
<< 37 of 54 >>

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;

?>

Submitted by Lao (not verified) on March 24, 2011 - 7:44pm.

Thank you for sharing information like this. It’s very useful to me. Visit www.mgupload.net for more information about data mapping

Lao
www.mgupload.net

Submitted by Books and Manuals (not verified) on May 19, 2011 - 7:35pm.

I'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.

Vivian
Marks Web
www.imarksweb.net

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.