Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Last active August 26, 2017 12:42
Show Gist options
  • Save jasondmoss/7344247 to your computer and use it in GitHub Desktop.
Save jasondmoss/7344247 to your computer and use it in GitHub Desktop.
Simple WordPress Paginator
<?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