Last active
October 1, 2021 02:28
-
-
Save Daniel-Walsh/274dda3d082cf47c403db89a6c8e2220 to your computer and use it in GitHub Desktop.
Basic post pagination template #wordpress #php #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 | |
/** | |
* Pagination template part. | |
* | |
* Injects the required classes to properly render accessible pagination buttons akin to the theme. Uses Bootstrap 4 and Fontawesome. | |
* | |
* @package WordPress | |
*/ | |
$paginate_classes = ' btn btn-primary btn-sm py-2 px-3 mx-1 '; | |
// When pulling in the pagination links, add screen reader text to make them accessible. | |
$paginate_links = paginate_links( | |
array( | |
'prev_text' => '<span class="fa fa-arrow-left mr-2"></span> Prev', | |
'next_text' => 'Next <span class="fa fa-arrow-right ml-2"></span>', | |
'before_page_number' => '<span class="sr-only">Go to Page </span>', | |
'type' => 'array', | |
) | |
); | |
?> | |
<?php if ( $paginate_links ) : ?> | |
<div id="pagination" class="d-flex justify-content-center"> | |
<?php | |
foreach ( $paginate_links as $paginate_link ) : | |
$paginate_active_class = ( false !== strpos( $paginate_link, 'aria-current="page"' ) ) ? ' active ' : ''; | |
$pos = strpos( $paginate_link, 'page-numbers' ); | |
$paginate_link = substr( $paginate_link, 0, $pos ) . $paginate_classes . $paginate_active_class . substr( $paginate_link, $pos ); | |
echo wp_kses_post( $paginate_link ); | |
endforeach; | |
?> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment