确定页面内容类型
我正在 Drupal 6 中工作。
我需要在用户位于博客页面上时添加特定块。听起来很简单,但它却让我发疯。
当用户查看博客概述或单个博客条目时,需要显示该块。
我最初认为我可以按页面名称过滤它,因此它仅在页面 = /blog/ 时出现。不幸的是,这仅适用于博客概述页面;各个博客条目页面都有自己的 URL(默认为 /node/,但将更改为所有者想要的任何内容)。
再用谷歌搜索一下,我发现了 $node->type=='blog' ,它应该表明我在博客条目页面上,但似乎不起作用。
在 admin/build/block/configure 页面中,我将页面可见性设置为 PHP 模式,PHP 代码如下:
<?php
return ($node->type == 'blog');
?>
但这似乎不起作用,即使我在模板中 print_r($node) ,它确实显示类型==博客。
我还在上面添加了 strpos($_SERVER['REQUEST_URI','blog') ,但当然,由于第一个条件不起作用,添加第二个条件也无济于事。
感觉应该有一个明显的答案,但我就是找不到。谁能帮我一下。谢谢。
I'm working in Drupal 6.
I have a requirement to add a particular block when the user is on a blog page. Sounds simple enough, but it's been driving me mad.
The block needs to be shown when the user is viewing a blog overview or an individual blog entry.
I initially thought I could filter it by page name so it only appears when page = /blog/. Unfortunately, that only applies to the blog overview page; the individual blog entry pages have their own URLs (default is /node/ but will be changed to whatever the owner wants).
A bit more googling, and I found out about $node->type=='blog' which should pick up the fact that I'm on a blog entry pages, but doesn't seem to work.
In the admin/build/block/configure page I have page visibility set to PHP mode, and PHP code as follows:
<?php
return ($node->type == 'blog');
?>
but that doesn't seem to work, even though if I print_r($node) in the template, it does show type==blog.
I also added strpos($_SERVER['REQUEST_URI','blog') to the above, but of course since the first condition isn't working, adding the second won't help.
It feels like there should be an obvious answer, but I just can't find it. Can anyone help me out. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面代码的问题是,当您运行该块的代码时,它不会有可用的 $node 变量。您需要执行类似的操作才能将其添加到博客节点。
Your problem with the above code, is that when you run the code for the block, it wont have the $node variable available. You need to do something like this to add it to blog nodes.