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

How to display news sorted by date?


Go to End


3 Posts   4278 Views

Avatar
HarryKC

Community Member, 8 Posts

17 December 2008 at 2:36am

I would like to display news sorted by date instead of the order they are in the CMS.

Avatar
(deleted)

Community Member, 473 Posts

17 December 2008 at 7:23am

I'm assuming that you're using the News articles from the tutorial.

One way of doing this is to add your own method to the ArticleHolder in ArticleHolder.php, something like

function OrderedChildren() {
	return DataObject::get('ArticlePage', 'ParentID = ' . $this->ID, 'Date DESC');
}

Then, in your template, instead of using <% control Children %>, you'll use <% control OrderedChildren %>

Avatar
HarryKC

Community Member, 8 Posts

17 December 2008 at 6:46pm

Thanks! Yes this was from the tutorial.