Created
April 13, 2022 12:58
-
-
Save ravismakwana/0ccc7ca3fdc5f266018fd36a8e263922 to your computer and use it in GitHub Desktop.
Post pagination with bootstrap 5
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
<?php | |
function bootstrap_pagination(){ | |
$allowed_tags = [ | |
'span' => [ | |
'class' => [] | |
], | |
'ul' =>[ | |
'class' => [], | |
], | |
'li' =>[ | |
'class' => [], | |
], | |
'a' => [ | |
'class' => [], | |
'href' => [], | |
], | |
]; | |
$args = [ | |
'type' => 'array', | |
'prev_next' => true, | |
'prev_text' => __('« Prev'), | |
'next_text' => __('Next »'), | |
]; | |
$pages = paginate_links($args); | |
if (is_array($pages)) { | |
$pagination = '<ul class="pagination justify-content-center">'; | |
foreach ($pages as $page) { | |
$current_class = strpos($page, 'current') ? 'active' : ''; | |
$pagination .= '<li class="page-item '.$current_class.'">' . str_replace('page-numbers', 'page-link', $page) . '</li>'; | |
} | |
$pagination .= '</ul>'; | |
} | |
printf('<nav class="asgard-pagination">%s</nav>', wp_kses($pagination, $allowed_tags)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment