Last active
August 26, 2017 12:42
-
-
Save jasondmoss/7344247 to your computer and use it in GitHub Desktop.
Simple WordPress Paginator
This file contains hidden or 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 | |
/** | |
* Custom pagination. | |
* | |
* @param integer $total Total number of pages | |
* @param boolean $echo Echo or return result? | |
* | |
* @return void | |
* @access public | |
*/ | |
function paginator($total, $echo = false) | |
{ | |
$paginator = ''; | |
if ($total > 1) { | |
if (!$currentPage = get_query_var('paged')) { | |
$currentPage = 1; | |
} | |
$link = get_option('permalink_structure'); | |
$format = empty($link) ? '&page=%#%' : 'page/%#%/'; | |
$paginator = paginate_links([ | |
'base' => get_pagenum_link(1) .'%_%', | |
'format' => $format, | |
'current' => $currentPage, | |
'total' => $total, | |
'mid_size' => 4, | |
'type' => 'plain' | |
]); | |
} | |
return ($echo) ? e($paginator) : $paginator; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment