Skip to content

Instantly share code, notes, and snippets.

@OzzyCzech OzzyCzech/om.php
Created Jan 26, 2012

Embed
What would you like to do?
Show paginator in wordpress without plugin
<?php
/**
* Generate pagination link from $wp_query
* @param $wp_query
* @return string
*/
public static function paginator($wp_query)
{
$pagination = array(
'base' => str_replace('91919', '%#%', get_pagenum_link(91919)),
'format' => '',
'total' => ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']),
'current' => absint(get_query_var('paged')),
'end_size' => 2,
'mid_size' => 2,
);
$total_pages = (!absint($wp_query->max_num_pages)) ? 1 : absint($wp_query->max_num_pages);
if ($total_pages > 1) {
$after = (absint(get_query_var('paged')) == 0) ? '<a href="' . get_pagenum_link('2') . '" class="next page-numbers">' . __('Next &raquo;') . '</a>' : '';
return '<div class="paginator">' . paginate_links($pagination) . $after . '</div>';
} else {
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.