Skip to content

Instantly share code, notes, and snippets.

@punit5658
Last active September 19, 2018 12:53
Show Gist options
  • Save punit5658/34de9637239dd1f397d550bb56afb810 to your computer and use it in GitHub Desktop.
Save punit5658/34de9637239dd1f397d550bb56afb810 to your computer and use it in GitHub Desktop.
WordPress pagination when we have created page same slug as post type
<?php
function pnavigation( $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' => '&larr;',
'next_text' => '&rarr;',
) );
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<ul class="pagination pagination-lg">';
foreach ( $pages as $page ) {
echo "<li>$page</li>";
}
echo '</ul>';
}
}/* end page navi */
function pagination_rewrite() {
add_rewrite_rule('{post-type}/page/?([0-9]{1,})/?$', 'index.php?pagename={post-type}&paged=$matches[1]', 'top');
}
add_action('init', 'pagination_rewrite');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment