Created
October 31, 2022 23:41
-
-
Save kodie/190917926f26ea89e65ad424f987fd63 to your computer and use it in GitHub Desktop.
Displays numeric pagination links in WordPress
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 | |
// 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