Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Show only 5 News on one Page

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

Page: 1
Go to End
Author Topic: 1046 Views
  • bezarre
    Community Member
    13 Posts

    Show only 5 News on one Page Link to this post

    Hello everyone,

    I started using silverstripe 3 weeks ago.

    I build a little news system and now I have a "problem", which I can't fix.

    I have a NewsHolder.php which extends the Page class

    class NewsHolder extends Page
    static $has_many = array (
          'News' => 'News'

    class NewsHolder_Controller extends Page_Controller


    At the moment the content shows all news. But I want only 5 news and a link on the bottom of the page to view the next 5 news.

    I wrote a function which I put in the NewsHolder_Controller:

    function getNews ()
          if (!isset($this->urlParams['ID']) || $this->urlParams['ID'] == 0)
             $start = 0;
             $start = $this->urlParams['ID']*10;
          $news = DataObject::get("News",'','','',array($start,10));

    Now I dont know how to move forward? When I am load http://localhost/mypage/news/1 (mypage is the silverstripe base folder and news the page name which uses the newsholder), I the error page. I don't want to use http://localhost/mypage/news/getNews/1 to switch the news.

    Can someone help me?

    Thank you

  • 3dgoo
    Community Member
    133 Posts

    Re: Show only 5 News on one Page Link to this post

    Have a look at this:


    Let me know if you have any questions.

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.