Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implement pagination using PaginatedList #1

Merged
merged 1 commit into from

2 participants

@svandragt

News items are usually paginated, so here's a simple paginated news litems list, and amended the templates to take advantage of it.

@richardsjoqvist

Great, thanks! There is a small problem with the comments in code/NewsHolder.php (line 75-76) that need to be fixed before I can merge this. Can you take a look at it?

@richardsjoqvist richardsjoqvist merged commit 31d10e8 into richardsjoqvist:master
@richardsjoqvist

I fixed the comment and merged. Thanks again!

@svandragt

Thanks sorry about the double comment (goto fail haha)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2014
  1. Implement pagination using PaginatedList

    Sander van Dragt authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 6 deletions.
  1. +11 −0 code/NewsHolder.php
  2. +6 −6 templates/Includes/NewsPagination.ss
View
11 code/NewsHolder.php
@@ -73,6 +73,17 @@ function NewsItems($limit = 10) {
}
/**
+ /**
+ * Returns NewsItems paginated
+ * @param integer $limit amount of news items
+ * @param integer $per_page news items per page
+ */
+ function NewsItemsPaginated($limit = 999, $per_page = 10) {
+ $news = $this->NewsItems($limit);
+ $items = new PaginatedList($news, $this->request);
+ $items->setPageLength($per_page);
+ return $items;
+ }
* Output the RSS feed for items connected to the requested news holder
*
* @param SS_HTTPRequest $request
View
12 templates/Includes/NewsPagination.ss
@@ -1,12 +1,12 @@
-<% if NewsItems.MoreThanOnePage %>
+<% if NewsItemsPaginated.MoreThanOnePage %>
<div id="PageNumbers">
<p>
- <% if NewsItems.NotFirstPage %>
- <a class="prev" href="$NewsItems.PrevLink" title="View the previous page">Prev</a>
+ <% if NewsItemsPaginated.NotFirstPage %>
+ <a class="prev" href="$NewsItemsPaginated.PrevLink" title="View the previous page">Prev</a>
<% end_if %>
<span>
- <% loop NewsItems.PaginationSummary(4) %>
+ <% loop NewsItemsPaginated.PaginationSummary(4) %>
<% if CurrentBool %>
$PageNum
<% else %>
@@ -19,8 +19,8 @@
<% end_loop %>
</span>
- <% if NewsItems.NotLastPage %>
- <a class="next" href="$NewsItems.NextLink" title="View the next page">Next</a>
+ <% if NewsItemsPaginated.NotLastPage %>
+ <a class="next" href="$NewsItemsPaginated.NextLink" title="View the next page">Next</a>
<% end_if %>
</p>
</div>
Something went wrong with that request. Please try again.