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.

Template Questions

How to display news sorted by date?


Reply

3 Posts   1933 Views

Avatar
HarryKC

17 December 2008 at 2:36am Community Member, 8 Posts

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

Avatar
simon_w

17 December 2008 at 7:23am Forum Moderator, 474 Posts

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

17 December 2008 at 6:46pm Community Member, 8 Posts

Thanks! Yes this was from the tutorial.