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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

paginatedList with offset


Go to End


1401 Views

Avatar
Phils

Community Member, 11 Posts

11 June 2014 at 6:04am

Edited: 11/06/2014 6:06am

Hi everybody,

I'm trying to do a News Archive Page. I want to get all News after offset 10 to show in a paginatedList. The first 10 News will show on the News Page.

So I tried:

public function getNewsArchiveList() {
	$NewsList = News::get()->limit(0,10);
	$paginatedList = new PaginatedList($NewsList, $this->request);
	$paginatedList->setPageLength(2);
	return $paginatedList;
}

That didn't work.

Then I tried:

public function getNewsArchiveList() {
	$NewsList = News::get();
	$paginatedList = new PaginatedList($NewsList, $this->request);
	$paginatedList->setPageLength(2);
        $paginatedList->setPageStart(10);
	return $paginatedList;
}

That only worked on page 1 of the PaginatedList. The other pages didn't switch the news. They all showed the same news than page 1.

In my .ss Template I got:

<% loop NewsArchiveList %>
  $Title
<% end_loop %>

<% if $NewsArchiveList .MoreThanOnePage %>
      <% if $NewsArchiveList.NotFirstPage %>
       	<a href="$NewsArchiveList .FirstLink">first</a>
        <a href="$NewsArchiveList .PrevLink">prev</a>
      <% end_if %>
      <% if $NewsArchiveList.NotLastPage %>
        <a href="$NewsArchiveList .NextLink">next</a>
        <a href="$NewsArchiveList .LastLink">last</a>
      <% end_if %>
<% end_if %>

Anybody got that to work before? I would very much appreciate every hint.

Thanks,
Philip