17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1350 Views |
-
Article Holder - date descending

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.
-
Re: Article Holder - date descending

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.
| 1350 Views | ||
|
Page:
1
|
Go to Top |


