Created
May 10, 2023 13:35
-
-
Save trueqap/b9ec28c265ea0ac09d612c49c7749622 to your computer and use it in GitHub Desktop.
WordPress Bootstrap Pagination
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 | |
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' => '«', | |
'next_text' => '»', | |
)); | |
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