3215 Posts in 848 Topics by 811 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1618 Views |
-
How to display news sorted by date?

17 December 2008 at 2:36am
I would like to display news sorted by date instead of the order they are in the CMS.
-
Re: How to display news sorted by date?

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 %>
-
Re: How to display news sorted by date?

17 December 2008 at 6:46pm
Thanks! Yes this was from the tutorial.
-
Re: How to display news sorted by date?

24 May 2013 at 11:51am
I know this topic is dated...but, the News Article tutorial is the same.
Simon_W, can you -or anyone- explain the function you gave for sorting? I'm just trying to learn php and I'm not following the logic.
return DataObject::get('ArticlePage', 'ParentID = ' . $this->ID, 'Date DESC')
- I understand this gets page-type 'ArticlePage'...and, the end sorts by date descending
~ What is the: 'ParentID = '. $this->ID
In addition to sorting the news, how would you display only the articles with a date field within a certain range? For example, articles that should only display for a short period of time (StartDate & EndDate), or hide those that expired yesterday (ExpireDate)...
Thank you
| 1618 Views | ||
|
Page:
1
|
Go to Top |

