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.

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   2325 Views

Avatar
Briohny

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.

Avatar
Liam

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 - http://doc.silverstripe.com/doku.php?id=private:recipes:pagination

Just add in the sort option in the query.

Avatar
Briohny

Community Member, 199 Posts

24 October 2008 at 6:03am

Perfect! Thank you LeeUmm!