From 2e5354c97eac399b2c978e6158ebdfbc80df40c7 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Wed, 12 Feb 2025 12:56:00 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feature:=20Pagination=20complete=20and?= =?UTF-8?q?=20functional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script.js | 32 ++++++++++++++++++++------------ assets/style.css | 7 +++++++ resource-filter.php | 14 ++++++++------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/assets/script.js b/assets/script.js index 112392b..cfb4f0f 100644 --- a/assets/script.js +++ b/assets/script.js @@ -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(''); + } $('.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); - }); }); diff --git a/assets/style.css b/assets/style.css index 7320f91..4e25046 100644 --- a/assets/style.css +++ b/assets/style.css @@ -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; diff --git a/resource-filter.php b/resource-filter.php index 21d790f..f3fa0f2 100644 --- a/resource-filter.php +++ b/resource-filter.php @@ -178,14 +178,14 @@ class ResourceFilterPlugin { 'format' => '?paged=%#%', 'prev_text' => '«', 'next_text' => '»', + 'type' => 'list' ]); - - if ($pagination_links) { - echo ''; - } ?> ' . $pagination_links . ''; + } } 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' : '', ]) ];