Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

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

Show only 5 News on one Page

Go to End

2 Posts   1437 Views


Community Member, 13 Posts

30 July 2010 at 12:30am

Edited: 30/07/2010 12:35am

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


Community Member, 135 Posts

5 August 2010 at 1:01pm

Have a look at this:

Let me know if you have any questions.