Community Documentation

Show block only when author is X

Last updated June 19, 2010. Created by add1sun on April 7, 2007.
Edited by j. ayen green. Log in to edit this page.

I used this for my blog section and I also used the script that makes the block visible for a certain type of node. This way the block only shows on pages that are blog pages and that have been made by a certain user.

<?php
function view_node($type = 'blog',$username) {
$match = FALSE;

if (
arg(0) == 'node' && is_numeric(arg(1))) {
   
$nid = arg(1);
    
$node = node_load(array('nid' => $nid));
     if (
$type == $node->type && $node->name == $username) {
       
$match = TRUE;
    }
}
return
$match;
}
?>

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here