Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Tutorial 2: Ordering the news and number of displayed items

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: 1443 Views
  • thrax
    Avatar
    Community Member
    32 Posts

    Tutorial 2: Ordering the news and number of displayed items Link to this post

    Hi guys,

    Maybe I've been awake too long staring at this screen but I swear I cannot see anywhere in Tutorial 2 that shows how to order the news posts!

    The problem I have: Using the news post setup (exactly as show in tutorial 2), whenever I create a new ArticlePage it orders itself (in the CMS and on the news page) under the previous posts... how do I get them to run in order from most recently posted to oldest?

    Also... is there a way (already documented preferably) to show say.. the last 10 news items only, and have the rest off the page in record sets (im not sure if thats the right terminology sorry), eg: small number at the bottom of them page where you can go back and see previously posted news.

    Thanks in advance....

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Tutorial 2: Ordering the news and number of displayed items Link to this post

    I think it shows this code in the tutorial

    DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num).

    Which translates to

    GET ALL of the 'ArticlePages' whose Parent = X. Order it by the Date Desc. And $num is the limit of how much you want to limit it to. If you want all the pages you can just get rid of the last parameter - this will get all. If you make $num 10 then it will get the latest 10.

    So the format in SQL terms is

    DataObject::get( <TYPE OF PAGE>, <FILTER>, <SORT OPTION>, <JOIN OPTION>, <LIMIT>);

    Join is more compilcated so you can leave it blank. See http://doc.silverstripe.com/doku.php?id=datamodel&s=dataobject

  • thrax
    Avatar
    Community Member
    32 Posts

    Re: Tutorial 2: Ordering the news and number of displayed items Link to this post

    Thanks mate, got it sorted now with your help!

    1443 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.