-
-
Save mr-fan/666bf822a59d87633f02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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