I wrote lately some instruction to display a block in two different cases:
- when the content type is [my-content-1] or [my-content-2]
- when the url is /my_page1 or /my_page2
I found how to do it in Block visible for Specific Content Type AND Specific URL.
<?php
$match = FALSE;
$types = array('content-petites_annonces' => 1);
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;
}
}
if (substr($_SERVER["REQUEST_URI"], 0, 10) == '/petitesan')
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/content-petites_annonces
")
{ $match = TRUE;}
return $match;
?>
It works fine, I could declare several content types in the first array (I've got 6).
But as for the urls, it only works if I repeat the same line every time (and there are loads of them).
if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page1
")
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page2
")
{ $match = TRUE;}
...
I am certain there is a more mutualized way to do it.
Is there also a mean to get it working regardless of the pagination, i.e. whithout having to notify every time
if (substr($_SERVER["REQUEST_URI"], 0) == "/my_page?page=X
")
{ $match = TRUE;}
Is the answer hidden in the 0, 10 in the precision about the request URI? I didn't even used that line.