确定页面内容类型

时间:2010-08-11 10:31:40

标签: drupal drupal-blocks

我在Drupal 6工作。

当用户在博客页面上时,我需要添加特定的块。听起来很简单,但这让我很生气。

当用户查看博客概述或单个博客条目时,需要显示该块。

我最初认为我可以按页面名称对其进行过滤,因此只有在页面= / blog / 时才会显示。不幸的是,这仅适用于博客概述页面;各个博客条目页面都有自己的URL(默认为/ node / ,但会更改为所有者想要的内容)。

更多谷歌搜索,我发现了$ node-> type =='blog',它应该知道我在博客条目页面上,但似乎没有用。

在admin / build / block / configure页面中,我将页面可见性设置为PHP模式,PHP代码如下:

<?php
return ($node->type == 'blog');
?>

但这似乎不起作用,即使我在模板中使用print_r($ node),它也会显示type == blog。

我还在上面添加了strpos($ _ SERVER ['REQUEST_URI','blog'),但当然由于第一个条件不起作用,添加第二个条件无济于事。

感觉应该有一个明显的答案,但我找不到它。谁能帮我吗。感谢。

1 个答案:

答案 0 :(得分:1)

上述代码的问题在于,当您运行块的代码时,它不会有$ node变量可用。您需要执行类似的操作才能将其添加到博客节点。

<?php
    // This code checks the internal url, which for nodes always will be node/[nid].
    // Last condition: don't display the block on node edit forms etc.
    if (arg(0) == 'node' && is_numeric(arg(1)) && empty(arg(2))) {
      $node = node_load(arg(1));
      return $node->type == 'blog';
    }
?>
相关问题