Block visibility in multiblog sites D6

Last modified: May 17, 2009 - 16:59

Here is a php snippet to use in D6 if you have more than one blogs in your drupal site and you wish to handle block visibility.
I checked all php snippets and this was missing.

the following example is for blog/1 and user= userName

<?php
$match
= FALSE;
$type = 'blog';
if (
arg(0)=='blog' && arg(1) == 1)
return
true;
if (
arg(0) == 'node' && is_numeric(arg(1))) {
    
$nid = arg(1);
    
$node = node_load(array('nid' => $nid));
   
$nodetype = $node->type;
   
$name = $node->name;
     if (
$type == $nodetype && $name == 'userName') {
       
$match = TRUE;
    }
}

return
$match;
?>

the following example is for blog/2 and user = John

<?php
$match
= FALSE;
$type = 'blog';
if (
arg(0)=='blog' && arg(1) == 2)
return
true;
if (
arg(0) == 'node' && is_numeric(arg(1))) {
    
$nid = arg(1);
    
$node = node_load(array('nid' => $nid));
   
$nodetype = $node->type;
   
$name = $node->name;
     if (
$type == $nodetype && $name == 'John') {
       
$match = TRUE;
    }
}

return
$match;
?>

So basicaly, suppose one has 2 blogs in one drupal site (with 2 different users) and wishes to make 1 block for each blog that will display recent comments for that blog. This block should be visible when visiting the appropriate blog. When visiting blog/1 and all nodes included in it we wish to see "Recent comments for blog/1" block and when we visit blog/2 and all nodes included in it, we wish to see "Recent comments for blog/2".

So we are giving the php 3 elements : type, url and userName.That is if the type is blog, the url == 1 (blog/1) and the user that uploads content = Username, make this block visible on blog/1.

simple as that, enjoy :)

 
 

Drupal is a registered trademark of Dries Buytaert.