代码之家  ›  专栏  ›  技术社区  ›  Spudley Pat

确定页面内容类型

  •  0
  • Spudley Pat  · 技术社区  · 15 年前

    我在Drupal6工作。

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

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

    我最初认为我可以按页面名称过滤它,这样它只在page=/blog时出现/ . 不幸的是,这只适用于博客概述页面;每个博客条目页面都有自己的url(默认值为/node)/ 但将被改变为任何业主想要的)。

    再搜索一下,我发现了$node->type=='blog'应该会发现我在一个blog条目页面上,但似乎不起作用。

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

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

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

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

    1 回复  |  直到 12 年前
        1
  •  1
  •   googletorp    15 年前

    <?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';
        }
    ?>