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   2336 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
simon_w

Forum Moderator, 474 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.