mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Fix pagination styling, add-to-cart class/data-attr mismatch, shop.php pagination
This commit is contained in:
+39
-20
@@ -204,29 +204,48 @@ function paginate($totalItems, $currentPage, $perPage = ITEMS_PER_PAGE) {
|
||||
*/
|
||||
function renderPagination($pagination, $baseUrl) {
|
||||
if ($pagination['total_pages'] <= 1) return '';
|
||||
|
||||
$html = '<nav class="pagination"><ul>';
|
||||
|
||||
// Previous
|
||||
if ($pagination['has_prev']) {
|
||||
$html .= '<li><a href="' . $baseUrl . '?page=' . ($pagination['current_page'] - 1) . '">« Previous</a></li>';
|
||||
}
|
||||
|
||||
// Page numbers
|
||||
for ($i = 1; $i <= $pagination['total_pages']; $i++) {
|
||||
if ($i == $pagination['current_page']) {
|
||||
$html .= '<li class="active"><span>' . $i . '</span></li>';
|
||||
} else {
|
||||
$html .= '<li><a href="' . $baseUrl . '?page=' . $i . '">' . $i . '</a></li>';
|
||||
|
||||
$cur = $pagination['current_page'];
|
||||
$total = $pagination['total_pages'];
|
||||
// baseUrl may already contain query params; append page with &
|
||||
$sep = strpos($baseUrl, '?') !== false ? '&' : '?';
|
||||
$url = fn($p) => $baseUrl . $sep . 'page=' . $p;
|
||||
|
||||
$btn = fn($href, $label, $active = false, $disabled = false) =>
|
||||
'<a href="' . ($disabled ? '#' : htmlspecialchars($href)) . '" style="'
|
||||
. 'display:inline-flex;align-items:center;justify-content:center;'
|
||||
. 'min-width:36px;height:36px;padding:0 10px;border-radius:6px;'
|
||||
. 'font-size:.875rem;font-weight:500;text-decoration:none;transition:all .15s;'
|
||||
. ($active ? 'background:#FF5E1A;color:#fff;cursor:default;' :
|
||||
($disabled ? 'background:transparent;color:#444;cursor:default;pointer-events:none;' :
|
||||
'background:#1e1e1e;color:#ccc;border:1px solid #333;'))
|
||||
. '">' . $label . '</a>';
|
||||
|
||||
$html = '<div style="display:flex;align-items:center;justify-content:center;gap:4px;padding:1.5rem 0;flex-wrap:wrap">';
|
||||
|
||||
// Prev
|
||||
$html .= $btn($url($cur - 1), '← Prev', false, !$pagination['has_prev']);
|
||||
|
||||
// Page numbers with ellipsis
|
||||
$pages = [];
|
||||
for ($i = 1; $i <= $total; $i++) {
|
||||
if ($i === 1 || $i === $total || abs($i - $cur) <= 2) {
|
||||
$pages[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
// Next
|
||||
if ($pagination['has_next']) {
|
||||
$html .= '<li><a href="' . $baseUrl . '?page=' . ($pagination['current_page'] + 1) . '">Next »</a></li>';
|
||||
$prev = null;
|
||||
foreach ($pages as $p) {
|
||||
if ($prev !== null && $p - $prev > 1) {
|
||||
$html .= '<span style="color:#555;padding:0 4px">…</span>';
|
||||
}
|
||||
$html .= $btn($url($p), $p, $p === $cur);
|
||||
$prev = $p;
|
||||
}
|
||||
|
||||
$html .= '</ul></nav>';
|
||||
|
||||
// Next
|
||||
$html .= $btn($url($cur + 1), 'Next →', false, !$pagination['has_next']);
|
||||
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user