Drupal:检索并打印节点名称(而不是类型)
我有一个在视图模块中创建的块,我在其中发布用户最近发表的评论(例如,用户 uid 1033 的五个最新评论)。我创建了自己的 tpl 文件,因此我可以自定义要显示的字段并且它可以工作。
它打印注释的前 140 个字符并链接到后面带有 #cid 的节点。
但在其下面,我想显示它发布在哪个节点类型中。我尝试使用以下代码:print $node->type;
但这——当然——只是打印节点类型,这不是特别人类可读的,所以我想要的是节点名称(来自数据库类“node_type”),但我就是不知道如何做到这一点。
有什么简单的方法或者我必须使用某种定制的查询/API 调用吗?
I’ve a block, created in the views module, where I post the most recent comments made by a user (e.g. the five most recent comments for user uid 1033). I’ve created my own tpl file so I can customize which fields I want to display and it works.
It prints the first 140 characters of the comment and link to the node with the #cid behind it.
But underneath that I want to show which node-type it is posted in. I tried by using this code:print $node->type;
but that – of cause – just prints the node type and that is not especially human readable so what I want is the node name (from the database class “node_type”) but I just can’t get my head around how to do that.
Is there any easy way or do I have to use some kind of customized query / API call??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看node_get_types() api 函数。
http://api.drupal.org /api/drupal/modules--node--node.module/function/node_get_types/6
Take a look at node_get_types() api function.
http://api.drupal.org/api/drupal/modules--node--node.module/function/node_get_types/6
您是否尝试过在视图中添加 Node:Type 字段?
Have you tried adding the Node:Type field inside the view?
除非您确实做了一些错误的事情,例如在 .tpl.php 文件中对每个文件执行完整的 node_load() 操作,否则您需要配置视图以显示节点类型。模板并不是要添加额外的数据,而只是格式化和布局其显示。
为了显示注释附加到的节点的类型,您需要
Unless your are doing something really wrong such as doing a full node_load() of each in your .tpl.php file, you need to configure your view to display the node type. Templates aren't mean to add additional data but only format and layout their display.
In order to display the type of the node a comment is attached to, you need to