Jump to:

23453 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Sort Article List Chronologically

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 885 Views
  • Scorpiankh
    Community Member
    60 Posts

    Sort Article List Chronologically Link to this post

    Is there any way to have an article list (ie; on an ArticleHolder page) displayed so it's sorted in chronological order with most recent articles displayed at the top?
    ...other than manually sorting the pages by dragging and dropping them up the list in the CMS

  • swaiba
    Forum Moderator
    1788 Posts

    Re: Sort Article List Chronologically Link to this post

    Assuming you are talking about... http://doc.silverstripe.org/tutorial:2-extending-a-basic-site

    something like this in your controller...

    function ArticlesOrderedByCreated() {
    return DataObject::get("ArticleHolder","","Created ASC");

    then this in your controller...

    <% if ArticlesOrderedByCreated %>
    <% control ArticlesOrderedByCreated %>
       $Date <br />
       $Author <br />
       $Content <br />
    <% end_control %>
    <% end_if %>

    every dataobject (including pages or anything you create) has a "Created" and "LastEditted" value set automatically when you create it and when you edit it.

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.