Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active August 10, 2016 01:25
Show Gist options
  • Save jrobinsonc/bb3829f9418d37c02a09 to your computer and use it in GitHub Desktop.
Save jrobinsonc/bb3829f9418d37c02a09 to your computer and use it in GitHub Desktop.
Wordpress helper: Show pagination
<?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