Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Multiple News

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

Page: 1
Go to End
Author Topic: 421 Views
  • Craftnet
    Avatar
    Community Member
    58 Posts

    [SOLVED] Multiple News Link to this post

    Hi,
    I try to do multiple news consisting of News, "NewsPage" and the news "DiscographyNews".

    I would like to be displayed by date.
    At the moment I found such a thing

    function LatestNews($num=10) {
       return DataObject::get("ArticlePage", "", "Date DESC", "", $num);   
    }

    Everything is good because it displays each note of the layout Articlepage (anywhere I would not put it)
    When I try insert this code:

    function LatestNews($num=10) {
       return DataObject::get("DiscographyPage", "", "Date DESC", "", $num);   
    }

    displays all DiscographyPage

    I would like to combine it into one to sort by date and display all at once on the home page

    I tried this:

    function LatestNews($num=10) {
       return DataObject::get("ArticlePage", "", "Date DESC", "", $num);
    return DataObject::get("DiscographyPage", "", "Date DESC", "", $num);      
    }

    But then retrieves only the first "return".

    It can be somehow unite?

    I find that but this not sort by date

    function LatestNews($num=15) {
    $articles = DataObject::get("ArticlePage", "", "Date DESC", "", $num);
    $disc = DataObject::get("DiscographyPage", "", "Date DESC", "", $num);

    $articles->merge($disc);
    return $articles->getRange(0, $num);
    }


    Struck-out text because: See post below

    Sorry for my bad English

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: [SOLVED] Multiple News Link to this post

    I answer myself but it may be useful to someone.

    I found a solution.
    In function LatestNews need to insert such a thing

    function LatestNews($num=15) {
       $sorcik = new DataObjectSet();
       $sorcik->merge(DataObject::get("ArticlePage", "", "Date DESC", "", $num));
       $sorcik->merge(DataObject::get("DiscographyPage", "", "Date DESC", "", $num));
       $sorcik->merge(DataObject::get("BiographyPage", "", "Date DESC", "", $num));
       $sorcik->sort('Date', 'DESC');
       return $sorcik->getRange(0, $num);
    }

    Now function LatestNews collects all the news of the code pages (in my case: ArticlePage, DiscographyPage and BiographyPage) and sorts them by date.

    Sorry for my bad English

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