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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Article Holder - date descending

Go to End

3 Posts   2194 Views


Community Member, 199 Posts

24 October 2008 at 1:51am

I'm sure there's an easy enough way but i can't figure it out. I want my article holder to display the articles in a date descending order. Rather than 'drag and dropping' in the CMS is there a piece of code i can add to the ArticleHolder.php ... "Date DESC" or something?

It's just that when you add a new ArticlePage, the CMS automatically places it at the bottom of the list and i want the most recent articles to appear on top of the ArticleHolder page without having to drag and drop every time.

Thanks in advance.


Community Member, 470 Posts

24 October 2008 at 4:18am

It shows you right in the same tutorial, assuming you copied number 2.

Add the function in your controller

function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;

Then instead of calling control children, you'd call control LatestNews.

You should also probably keep in mind some type of pagination so instead of doing the above, use the recipe here -

Just add in the sort option in the query.


Community Member, 199 Posts

24 October 2008 at 6:03am

Perfect! Thank you LeeUmm!