Skip to content

Instantly share code, notes, and snippets.

@kodie
Created October 31, 2022 23:41
Show Gist options
  • Save kodie/190917926f26ea89e65ad424f987fd63 to your computer and use it in GitHub Desktop.
Save kodie/190917926f26ea89e65ad424f987fd63 to your computer and use it in GitHub Desktop.
Displays numeric pagination links in WordPress
<?php
// Displays numeric pagination links
function numeric_pagination($query = null, $echo = true) {
if (!$query) {
global $wp_query;
$query = $wp_query;
}
$total_pages = $query->max_num_pages;
$big = 999999999; // need an unlikely integer
$links = null;
if ($total_pages > 1) {
$current_page = max(1, get_query_var('paged'));
$links = paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
));
}
if ($echo) echo $links;
return $links;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment