【问题标题】:Display .PHP block on /blog but not inner blog pages在 /blog 上显示 .PHP 块,但不在内部博客页面上
【发布时间】:2014-11-19 10:52:39
【问题描述】:

我有一个块显示在我的主博客页面 (/blog) 和各个博客页面本身上。

我希望该块继续显示在主博客页面上而不是在单个博客页面上。

例如,该块应显示在 - this page 而不是 this page。

块.PHP如下:

<?php 
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));
$findme   = 'blog';
$pos = strpos($link, $findme);
if ($pos !== false) {
  RETURN TRUE;
}
$node = node_load(arg(1));
if($node->type == 'blog') {
  return TRUE;
}
?>

【问题讨论】:

    标签: php html drupal drupal-7


    【解决方案1】:

    进入 /admin/structure/blocks,搜索块的名称,配置,在 Pages 选项卡中,选择“仅列出的页面”,然后在文本区域中写下主博客页面的标题

    【讨论】:

    • 有时我们会被复杂性所蒙蔽!谢谢你让我睁开眼睛!!!
    【解决方案2】:

    不要使用 php 过滤器选项,而是转到给定块的配置页面。

    在可见性设置下,在“页面”字段集中。选择“仅在列出的页面上”。在下面的文本区域中输入博客的路径,在您的示例中为“博客”。 如果您希望此块仅出现在子页面上,您可以输入“blog/*”。

    或者,如果这是一个程序创建的块,在 hook_block_info 的实现中。将以下键添加到块数组中。

    'visibility' => BLOCK_VISIBILITY_LISTED,
    'pages' => 'blog',
    

    例子

    function hook_block_info() {
      $blocks = array();
    
      $blocks['example_block'] = array(
        'info' => t('Example block'),
        'status' => 1,
        'region' => 'content',
        'visibility' => BLOCK_VISIBILITY_LISTED,
        'pages' => 'blog',
        'cache' => DRUPAL_CACHE_GLOBAL,
        'weight' => 3,
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-23
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 2020-10-14
      • 2016-01-29
      • 1970-01-01
      相关资源
      最近更新 更多