用于列出节点和注释的 Drupal 视图
我想创建一个视图,显示论坛中的最新帖子以及任何最新评论。评论和帖子都将显示在同一视图中。我可以这样做吗?
预先感谢,
本
I want to create a view that shows the latest posts in a forum and also any latest comments. The comments and the posts would all show in the same view. Is it possible for me to do this?
Thanks in advance,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
本质上:不。视图要求您在第一步中选择一个主要资源:您(除其他外)选择使用节点或评论。
但是,通过一些(丑陋的)配置,您可以加载节点附带的注释。每个结果看起来像,节点 - 注释,例如:
等等。通过一些样式,您可以让它在单独的行中显示注释和节点。
然而,这是丑陋和黑客的。我的建议:编写一个简单的模块,公开一个块或一个菜单+页面,并对数据库执行两个简单(且简单)的查询:
SELECT nid, title, ... FROM {nodes} LIMIT 10< /code> 和
SELECT nid, name AS title, ... FROM {comments} LIMIT 10
然后将这两者混合起来。或者,使用一些(更复杂的)SQL 魔法,您甚至可以连接两个表并创建奇特的结果,例如按节点或注释的创建日期排序。In essence: no. Views requires you to choose one main resource in the first step: you there (amongst others) choose to go with either nodes, or comments.
However, with some (ugly) configuration, you can load the comments that go with nodes. Each result would look like, Node - Comment, e.g.:
and so on. With some styling, you can then get it to show comments and nodes in separate rows.
However, this is ugly and hackish. My advise: write a simple module that either exposes a block, or a menu+page, and do two simple (and light) queries on the database:
SELECT nid, title, ... FROM {nodes} LIMIT 10
andSELECT nid, name AS title, ... FROM {comments} LIMIT 10
then mix these two up. Or, with some (more complex) SQL magic, you could even join the two tables and create fancy results that e.g. order by created date of either nodes or comments.使用 Drupal 7,您可以添加关系“最后评论”,然后将该字段添加到视图中。
With Drupal 7 you can add a relationship Last comment and then add that field to the view.
我看到的一个想法是使用 视图自定义字段 用 PHP 代码“附加”一个完全独立的视图。请参阅注释#4获取代码(在视图中对此功能的请求。有关代码示例)。
One idea I've seen is to use Views Custom Field to "attach" a wholly separate view with PHP code. See comment #4 for the code (in a request for this feature in Views. for a code example).