Last active
September 19, 2018 12:53
-
-
Save punit5658/34de9637239dd1f397d550bb56afb810 to your computer and use it in GitHub Desktop.
WordPress pagination when we have created page same slug as post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => '←', | |
'next_text' => '→', | |
) ); | |
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