Skip to content

Instantly share code, notes, and snippets.

@mr-fan
Forked from dewwwald/_A.md
Last active August 29, 2015 14:02
Show Gist options
  • Save mr-fan/666bf822a59d87633f02 to your computer and use it in GitHub Desktop.
Save mr-fan/666bf822a59d87633f02 to your computer and use it in GitHub Desktop.
<?php
//PAGINATION FOR PROCESSWIRE
//[pagename]-controller.php
/*************************************************************************************\
Remember to activate the pagination for the specific template.
\*************************************************************************************/
function simple_pagination() {
$limit = 4;
$page = wire('page');
$page_results = $page->children("limit={$limit}, sort=created");
$page_count = $page->children->count;
$total_pages = ceil($page_count / $limit);
if (has_pagination($total_pages)) {
$pagination = get_pagination($total_pages);
return $pagination;
}
return "false";
}
function has_pagination($total_pages) {
if ($total_pages <= 1) {
return false;
}
else {
return true;
}
}
function get_pagination($total_pages) {
$input = wire('input');
$page = wire('page');
$html = '';
$has_next = $input->pageNum < $total_pages;
$has_prev = $input->pageNum > 1;
if ($has_prev) {
$url = $page->url;
if ($input->pageNum > 2) {
$url .= "?page=".($input->pageNum - 1);
}
$html .= "<a href='{$url}'>Previous</a>";
}
if ($has_next) {
$html .= "<a href='{$page->url}?page=".($input->pageNum + 1)."'>Next</a>";
}
return $html;
}
?>
##Simple Pagination For Processwire
###ProcessWire Requirements
On the template you want pagination. Go to the url's tab where you will have to:
- Activate Allow Page Numbers.
- Activate Allow URL Segments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment