0

我在 Drupal 6 中工作。

当用户在博客页面上时,我需要添加一个特定的块。听起来很简单,但它一直让我发疯。

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

我最初以为我可以按页面名称过滤它,所以它只在 page = /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') ,但是当然由于第一个条件不起作用,添加第二个也无济于事。

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

4

1 回答 1

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';
    }
?>
于 2010-08-11T10:53:06.657 回答