Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasghodsian/e70b7bff34310b1caa4cdba833ced853 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/e70b7bff34310b1caa4cdba833ced853 to your computer and use it in GitHub Desktop.
[Wordpress] Bootstrap 4+ Pagination
/**
* Bootstrap 4+ Pagination for Wordpress
*
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*
* @param integer $paged
* @param integer $max_num_pages
* @param string $wrap_classe
* @param integer $unlikely
* @return html
*/
function bt_pagination( $paged, $max_num_pages, $wrap_classe = "justify-content-center" , $unlikely = 999999999) {
$pages = paginate_links([
'base' => str_replace( $unlikely, '%#%', esc_url( get_pagenum_link( $unlikely ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $max_num_pages,
'type' => 'array',
'prev_next' => true,
'prev_text' => __('Föregående','presentkort'),
'next_text' => __('Nästa','presentkort'),
]);
if ( !is_array( $pages ) )
return false;
$html = '<nav aria-label="Page navigation"><ul class="pagination '.$wrap_classe.'">';
foreach ( $pages as $page ) {
$active = "";
if (strpos($page, 'current') !== false)
$active = " active";
$page = str_replace(['page-numbers', 'current'], ['page-link', ''], $page); // replace wp classes
$html .= '<li class="page-item'.$active.'">'.$page.'</li>';
}
$html .= '</ul></nav>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment