Skip to content

Instantly share code, notes, and snippets.

@trueqap
Created May 10, 2023 13:35
Show Gist options
  • Save trueqap/b9ec28c265ea0ac09d612c49c7749622 to your computer and use it in GitHub Desktop.
Save trueqap/b9ec28c265ea0ac09d612c49c7749622 to your computer and use it in GitHub Desktop.
WordPress Bootstrap Pagination
<?php
class BootstrapPagination {
public static function render() {
global $wp_query;
$current = max(1, absint(get_query_var('paged')));
$pagination = paginate_links(array(
'base' => str_replace(PHP_INT_MAX, '%#%', esc_url(get_pagenum_link(PHP_INT_MAX))),
'format' => '?paged=%#%',
'current' => $current,
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
));
if (!empty($pagination)) {
$output = '<nav aria-label="Page navigation">
<ul class="pagination">';
foreach ($pagination as $key => $page_link) {
$output .= '<li class="page-link' . (strpos($page_link, ' current') !== false ? ' active' : '') . '">' . $page_link . '</li>';
}
$output .= '</ul></nav>';
return apply_filters('sa_bootstrap_paginate_links', $output);
}
return '';
}
}
// echo BootstrapPagination::render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment