Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Article Holder - date descending

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

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

Page: 1
Go to End
Author Topic: 1498 Views
  • Briohny
    Avatar
    Community Member
    199 Posts

    Article Holder - date descending Link to this post

    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.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Article Holder - date descending Link to this post

    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.

  • Briohny
    Avatar
    Community Member
    199 Posts

    Re: Article Holder - date descending Link to this post

    Perfect! Thank you LeeUmm!

    1498 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.