Last active
February 17, 2020 13:03
-
-
Save MWDelaney/ce9e523b3f1bdf57b3180c9b24b73170 to your computer and use it in GitHub Desktop.
Some `facetwp_pager_html` + bootstrap pagination hotness
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 | |
namespace App; | |
add_filter( 'facetwp_pager_html', function( $output, $params ) { | |
$output = '<nav aria-label="Resources Pagination"><ul class="pagination mt-5">'; | |
$page = $params['page']; | |
$i = 1; | |
$total_pages = $params['total_pages']; | |
$limit = ($total_pages >= 5) ? 3 : $total_pages; | |
$prev_disabled = ($params['page'] <= 1) ? 'disabled' : ''; | |
$output .= '<li class="page-item ' . $prev_disabled . '"><a class="facetwp-page page-link" data-page="' . ($page - 1) . '">Prev</a></li>'; | |
$loop = ($limit) ? $limit : $total_pages; | |
while($i <= $loop) { | |
$active = ($i == $page) ? 'active' : ''; | |
$output .= '<li class="page-item ' . $active . '"><a class="facetwp-page page-link" data-page="' . $i . '">' . $i . '</a></li>'; | |
$i++; | |
} | |
if($limit && $total_pages > '3') { | |
$output .= ($page > $limit && $page != ($total_pages - 1) && $page <= ($limit + 1)) ? '<li class="page-item active"><a class="facetwp-page page-link" data-page="' . $page . '">' . $page . '</a></li>' : ''; | |
$output .= '<li class="page-item disabled"><a class="facetwp-page page-link">...</a></li>'; | |
$output .= ($page > $limit && $page != ($total_pages - 1) && $page > ($limit + 1)) ? '<li class="page-item active"><a class="facetwp-page page-link" data-page="' . $page . '">' . $page . '</a></li>' : ''; | |
$output .= ($page > $limit && $page != ($total_pages - 1) && $page != ($total_pages - 2) && $page > ($limit + 1)) ? '<li class="page-item disabled"><a class="facetwp-page page-link">...</a></li>' : ''; | |
$active = ($page == ($total_pages - 1)) ? 'active' : ''; | |
$output .= '<li class="page-item ' . $active . '"><a class="facetwp-page page-link" data-page="' . ($total_pages - 1) .'">' . ($total_pages - 1) .'</a></li>'; | |
} | |
$next_disabled = ($page >= $total_pages) ? 'disabled' : ''; | |
$output .= '<li class="page-item ' . $next_disabled . '"><a class="facetwp-page page-link" data-page="' . ($page + 1) . '">Next</a></li>'; | |
$output .= '</ul></nav>'; | |
return $output; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment