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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Change sort order of PageComments


Go to End


4 Posts   1917 Views

Avatar
tmkp

Community Member, 42 Posts

26 February 2010 at 9:15am

Hi everybody,
i'm looking for a way to change the sort order of page comments from "newest first" to "oldest first". Seems like such a simple thing to do, but i couldn't find a solution.
What would be the correct/easiest way to do this, any pointers?
Thanks a bunch!
Andi

Avatar
Willr

Forum Moderator, 5523 Posts

26 February 2010 at 2:27pm

It appears sort order is hard coded in the query - On line 215 of PageCommentInterface

DataObject::get("PageComment", "\"ParentID\" = '" . Convert::raw2sql($this->page->ID) . "' $spamfilter $unmoderatedfilter", '"Created" DESC', "", $limit);

If you wanted to change it you would need to change the DESC to ASC. It would be better if that sort field was a static variable you could set like PageCommentInterface::sort_comments('Created ASC'); I guess. Might be a nice enhancement ticket.

Avatar
tmkp

Community Member, 42 Posts

2 March 2010 at 2:22am

Hey Willr,
thanks for looking into this.. I can't believe that nobody seems to have run into this issue before.
I agree, it would be great to have this option available without hacking the core.

Avatar
Willr

Forum Moderator, 5523 Posts

2 March 2010 at 11:31am

Just so we can track the issue - I've made http://open.silverstripe.org/ticket/5130. Should be simple to implement so when I next have a spare 2 mins to add it and test it'll be sorted.