Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Consolidated view of comments


7 Posts   316 Views


10 January 2014 at 6:20am Community Member, 65 Posts

Hello all,

Is it possible to show a consolidated view of all comments across a number of pages?

I have a site with comments enabled on a number of pages which is working really well. Now to make it easier to get an overview of all the comments I would like to show all comments for these pages on the PageHolder page. Is this possible?



10 January 2014 at 10:36pm Community Member, 65 Posts

Have tried using the below:

function AllComments($num=200) {
return DataObject::get("Comment", "ParentID >= 1", "Created DESC", "", $num);

But I need to filter the results where the ParentIDs ParentID = $this


10 January 2014 at 11:33pm (Last edited: 11 January 2014 1:37am), Community Member, 65 Posts

Tried getting the ID of the children for the holder page but not sure how to relate the two functions:

function SortedChildren() {
    $dosChildren = $this->Children();    
    if ($dosChildren)
    return $dosChildren;
function AllComments() {
   return DataObject::get("Comment", "ParentID = $dosChildren.ID", "Created DESC");

Is this along the right lines?

To clarify the scenario is:


- Page 1
- Comment 1
- Comment 2

- Page 2
- Comment 3
- Comment 4
- Comment 5

- Page 3
- Comment 6
- Comment 7

I want to show all comments on the Page holder.


11 January 2014 at 5:37pm Forum Moderator, 5511 Posts

In your case as you described you don't need to write any functions, you could do something like the following in your holder template

<% loop Children %>
<% if Comments %>
<% loop Comments.Sort('Created DESC') %>
<% include CommentsInterface_singlecomment %>
<% end_loop %>
<% else %>
<p>No comments</p>
<% end_if %>
<% end_loop %>


15 January 2014 at 5:36am (Last edited: 15 January 2014 6:13am), Community Member, 65 Posts

Thanks Willr but I'm getting a Server error - Sorry, there was a problem handling your request.

Switch on dev mode it seems that I need to add a has_one relationship between the Page and the Comment DataObject but adding this just throws another error.

Uncaught Exception: No has_one found on class 'Comment', the has_many relation from 'ScreenPage' to 'Comment' requires a has_one on 'Comment'

Do I need to add a relationship back to the page?


15 January 2014 at 8:28am Forum Moderator, 5511 Posts

Got the latest version of comments? That was fixed in


16 January 2014 at 12:25am Community Member, 65 Posts

Nope. That's sorted it. Thanks Willr.