diff options
| author | ilotterytea <iltsu@alright.party> | 2025-12-10 15:09:47 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-12-10 15:09:47 +0500 |
| commit | 78ccc7e7db5fca5a1ff9bb63ef64b015f3afb1f3 (patch) | |
| tree | 1954381e4fcdfc4c1ae02674524bdd8892dc1a38 | |
| parent | 23da921c43b1c925710b55f93b87fef92dedd179 (diff) | |
feat: new pagination
| -rw-r--r-- | lib/partials.php | 58 | ||||
| -rw-r--r-- | static/style.css | 7 |
2 files changed, 54 insertions, 11 deletions
diff --git a/lib/partials.php b/lib/partials.php index 2d6cd44..12aa23d 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -162,23 +162,59 @@ function html_navigation_search() function html_pagination(int $total_pages, int $current_page, string $redirect) { + if ($total_pages < 1) { + return; + } + if (str_contains($redirect, "?")) { $redirect .= "&p="; } else { $redirect .= "?p="; } - if ($total_pages > 1) { - echo '' ?> - <div class="pagination"> - <?php if ($current_page > 1): ?> - <a href="<?= $redirect . ($current_page - 1) ?>">[ prev ]</a> - <?php endif; ?> - <?php if ($current_page < $total_pages): ?> - <a href="<?= $redirect . ($current_page + 1) ?>">[ next ]</a> - <?php endif; ?> + echo '<div class="pagination">'; - </div> - <?php ; + if ($current_page > 1) { + echo '<a href="' . $redirect . ($current_page - 1) . '"><</a>'; + } + + echo "<a href='{$redirect}1'>" . ($current_page == 1 ? "<b>1</b>" : 1) . '</a>'; + + $max = 5; + $range = 2; + + $start = max(2, $current_page - $range); + $end = min($total_pages - 1, $current_page + $range); + + if ($current_page <= $range) { + $start = 2; + $end = min($total_pages - 1, $max); + } + + if ($current_page > $total_pages - $range) { + $start = max(2, $total_pages - $max); + $end = $total_pages - 1; + } + + if ($start > 2) { + echo '...'; } + + for ($i = $start; $i <= $end; $i++) { + echo "<a href='{$redirect}$i'>"; + echo $i == $current_page ? "<b>$i</b>" : $i; + echo '</a>'; + } + + if ($end < $total_pages - 1) { + echo '...'; + } + + echo "<a href='{$redirect}$total_pages'>" . ($current_page == $total_pages ? "<b>$total_pages</b>" : $total_pages) . '</a>'; + + if ($current_page < $total_pages) { + echo '<a href="' . $redirect . ($current_page + 1) . '">></a>'; + } + + echo '</div>'; }
\ No newline at end of file diff --git a/static/style.css b/static/style.css index 08ec9ef..7cc782f 100644 --- a/static/style.css +++ b/static/style.css @@ -497,6 +497,13 @@ a.box:hover { vertical-align: middle; } +.pagination { + display: flex; + gap: 16px; + flex-direction: row; + justify-content: space-around; +} + /** --------------------------------- SOMETHING FROM TAILWINDCSS |
