Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » show 2° and 3° news in homepage

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

Page: 1
Go to End
Author Topic: 1059 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    show 2° and 3° news in homepage Link to this post

    Hi!

    I follow guide to show in my home page the last 3 news. If I want show the second and the third news and not the first how can I modify query?

    function LatestNews($num=3) {
          $news = DataObject::get_one("NewsHolder");
          return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
       }

    help please..

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: show 2° and 3° news in homepage Link to this post

    Couple ways to do this, best would be to set the offset in the query.

    DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", "1,$num");

    If you want to don't want to modify that query then you could skip the first in the template as well

    <% control LatestNews %>
    <% if First %>
    <% else %>
    DO STUFF. Will skip the first one
    <% end_if %>
    <% end_control %>

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: show 2° and 3° news in homepage Link to this post

    Hi Willr,

    thank for your solution!!It's great!!

  • fraxter
    Avatar
    Community Member
    8 Posts

    Re: show 2° and 3° news in homepage Link to this post

    Hi,

    could You help me regarding to showing news on home page... I'd like to get 5 latest news in one box but only one news should be displayed at the same time and news should change every 5 seconds... Could somebody help me how could I receive this goal?

    Many thanks in advance
    Peter

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