✨feature: Pagination complete and functional
This commit is contained in:
@@ -75,8 +75,14 @@ jQuery(document).ready(function ($) {
|
||||
$('#result-count').text(response.count);
|
||||
|
||||
// Update pagination
|
||||
if (response.pagination) {
|
||||
if (response.pagination && response.pagination.length > 0) {
|
||||
// Clear and update pagination container
|
||||
if (!$('.pagination').length) {
|
||||
$('#resource-results').after('<div class="pagination"></div>');
|
||||
}
|
||||
$('.pagination').html(response.pagination.join(''));
|
||||
} else {
|
||||
$('.pagination').html(''); // Clear pagination if no links are needed
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -120,6 +126,19 @@ jQuery(document).ready(function ($) {
|
||||
$('#sort-order').on('change', function () {
|
||||
triggerFiltering();
|
||||
});
|
||||
|
||||
|
||||
// Handle pagination click
|
||||
$(document).on('click', '.pagination a', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Extract the page number from the link
|
||||
let pagedMatch = $(this).attr('href').match(/paged=(\d+)/);
|
||||
let paged = pagedMatch ? pagedMatch[1] : 1; // Default to page 1 if no match is found
|
||||
|
||||
// Trigger filtering for the selected page
|
||||
triggerFiltering(paged);
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
@@ -148,15 +167,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Handle pagination click
|
||||
$(document).on('click', '.pagination a', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Extract the page number from the link
|
||||
let paged = $(this).attr('href').match(/paged=(\d+)/)[1];
|
||||
|
||||
// Trigger filtering for the selected page
|
||||
triggerFiltering(paged);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -130,6 +130,13 @@
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.pagination ul {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.pagination a,
|
||||
.pagination span {
|
||||
margin: 0 5px;
|
||||
|
||||
@@ -178,14 +178,14 @@ class ResourceFilterPlugin {
|
||||
'format' => '?paged=%#%',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'type' => 'list'
|
||||
]);
|
||||
|
||||
if ($pagination_links) {
|
||||
echo '<div class="pagination">' . $pagination_links . '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if ($pagination_links) {
|
||||
echo '<div class="pagination">' . $pagination_links . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
@@ -329,10 +329,12 @@ class ResourceFilterPlugin {
|
||||
'pagination' => paginate_links([
|
||||
'total' => $query->max_num_pages,
|
||||
'current' => isset($_POST['paged']) ? intval($_POST['paged']) : 1,
|
||||
'format' => '%#%',
|
||||
'format' => '?paged=%#%',
|
||||
'add_args' => [], // Pass additional query arguments
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'type' => 'array'
|
||||
'type' => 'array',
|
||||
// 'before_page_number' => (isset($_POST['paged']) && intval($_POST['paged']) === 1) ? '?paged=1' : '',
|
||||
])
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user