Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Last active October 31, 2021 02:37
Show Gist options
  • Save barbwiredmedia/722d38b42cbdba4a453c to your computer and use it in GitHub Desktop.
Save barbwiredmedia/722d38b42cbdba4a453c to your computer and use it in GitHub Desktop.
Wordpress pagination - paginate links http://codex.wordpress.org/Function_Reference/paginate_links No plugins required. Minor styling needed OR used bootstrap assitance: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
<?php echo paginate_links( $args ); ?>
<!--OR-->
<?php
//custom paginaiton with styling from bootstrap
function custom_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_next' => false,
'type' => 'array',
'prev_next' => TRUE,
'prev_text' => __('«'),
'next_text' => __('»'),
) );
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<ul class="pagination">';
foreach ( $pages as $page ) {
echo "<li>$page</li>";
}
echo '</ul>';
}
}?>
<?php echo custom_pagination();?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment