Search code examples
drupaldrupal-viewsdrupal-comments

Drupal view to list nodes and comments


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


Solution

  • 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.:

    • Can I have cheesburgers - First!
    • Can I have cheesburgers - No, I was first!!!111oneone
    • Can I have cheesburgers - LAME.

    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 and SELECT 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.