Created
April 18, 2019 02:29
-
-
Save ariakm25/bc65d1be0cab87645dc4e5187b9b171b to your computer and use it in GitHub Desktop.
Custom page navigation bootstrap for wordpress
This file contains hidden or 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
//Pagination | |
function bs_pagination( \WP_Query $wp_query = null, $echo = true ) { | |
if ( null === $wp_query ) { | |
global $wp_query; | |
} | |
$pages = paginate_links( [ | |
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ), | |
'format' => '?paged=%#%', | |
'current' => max( 1, get_query_var( 'paged' ) ), | |
'total' => $wp_query->max_num_pages, | |
'type' => 'array', | |
'show_all' => false, | |
'end_size' => 3, | |
'mid_size' => 1, | |
'prev_next' => true, | |
'prev_text' => __( '«' ), | |
'next_text' => __( '»' ), | |
'add_args' => false, | |
'add_fragment' => '' | |
] | |
); | |
if ( is_array( $pages ) ) { | |
// $paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' ); | |
$pagination = '<div class="pagination"><ul class="pagination">'; | |
foreach ( $pages as $page ) { | |
$pagination .= '<li class="page-item '.(strpos($page, 'current') !== false ? 'active' : '').'"> ' . str_replace( 'page-numbers', 'page-link', $page ) . '</li>'; | |
} | |
$pagination .= '</ul></div>'; | |
if ( $echo ) { | |
echo $pagination; | |
} else { | |
return $pagination; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment