Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created July 21, 2012 06:36
Show Gist options
  • Save claudiosanches/3154862 to your computer and use it in GitHub Desktop.
Save claudiosanches/3154862 to your computer and use it in GitHub Desktop.
Wordpress pagination
<?php
/**
* Pagination.
*/
function dfw_pagination() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1) {
$current_page = max( 1, get_query_var( 'paged' ) );
$pagination = '<div class="page-nav">';
$pagination .= paginate_links( array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'show_all' => false, // Show all items
'end_size' => 1, // Total of items displayed for the last few pages
'mid_size' => 2, // Total of items that will show along with the current page.
'prev_text' => __( '&laquo; Anterior', 'dfwtheme' ),
'next_text' => __( 'Próximo &raquo;', 'dfwtheme'),
));
$pagination .= '</div>';
// prevents duplicate bars in the middle of the url
$html = str_replace( '//page/', '/page/', $pagination );
echo $html;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment