Skip to content

Instantly share code, notes, and snippets.

@setuix
Created September 6, 2014 03:11
Show Gist options
  • Save setuix/53206c254d95cf987680 to your computer and use it in GitHub Desktop.
Save setuix/53206c254d95cf987680 to your computer and use it in GitHub Desktop.
// Pagination for a WordPress loop
$list = new WP_Query( $query_args );
$pagination = array(
'base' => str_replace( 99999, '%#%', get_pagenum_link( 99999 ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $list->max_num_pages,
'next_text' => 'next',
'prev_text' => 'previous'
);
echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';
// Pagination for anything
$list = range(1, 100);
$items_per_page = 12;
$pagination = array(
'base' => get_bloginfo( 'url' ) . '/mypage/%_%',
'format' => '?paged=%#%',
'current' => $_GET['current_page'],
'total' => ceil( max($list) / $items_per_page ),
'next_text' => 'go forth',
'prev_text' => 'go back'
);
echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment