Last active
August 10, 2016 01:25
-
-
Save jrobinsonc/bb3829f9418d37c02a09 to your computer and use it in GitHub Desktop.
Wordpress helper: Show pagination
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 | |
/** | |
* show_pagination | |
* | |
* Show pagination links. | |
* | |
* @author JoseRobinson.com | |
* @link https://gist.github.com/jrobinsonc/bb3829f9418d37c02a09 | |
* @version 2.0.0 | |
* @param object $custom_query An instance of the WP_Query class | |
* @param string $container HTML container for the pagination links | |
* @param array $config See https://codex.wordpress.org/Function_Reference/paginate_links | |
* @return void | |
*/ | |
function show_pagination($custom_query = null, $container = '<div class="pagination-box">%s</div>', $config = array()) | |
{ | |
if (null === $custom_query) | |
global $wp_query; | |
else | |
$wp_query = $custom_query; | |
$big = 999999999; | |
$pagination_array = array_merge(array( | |
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), | |
'format' => '?paged=%#%', | |
'current' => max(1, absint(get_query_var('paged'))), | |
'total' => $wp_query->max_num_pages, | |
// 'prev_text' => __('« Atras'), | |
// 'next_text' => __('Siguiente »') | |
), $config); | |
$pagination = paginate_links($pagination_array); | |
if (is_null($pagination)) | |
return; | |
printf($container, $pagination); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment