`
yanggaojiao
  • 浏览: 80311 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Page specific visibility settings

阅读更多

Display a block only to the user who's User ID = 1:

 

<?php
global $user;
if ($user->uid == 1){
    return TRUE;
}
else {
    return FALSE;
}
?>

 
Display a block only for a specific node (in this example, the node = story):

<?php
$match = FALSE;
$types = array('story' => 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;
    }
}
return $match;
?>

 

Display a block throughout all Forums:

<?php
if (arg(0) == 'forum') {
    return TRUE;
}
if (arg(0) == 'node' && ctype_digit(arg(1))) {
    $node = node_load(arg(1));
    if ($node->type == 'forum') {
        return TRUE;
    }
}
return FALSE;
?>

 

A variation: Display a block throughout all Blogs:

<?php
if (arg(0) == 'blog') {
    return TRUE;
}
if (arg(0) == 'node' && ctype_digit(arg(1))) {
    $node = node_load(arg(1));
    if ($node->type == 'blog') {
        return TRUE;
    }
}
return FALSE;
?>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics