Files
mataba/shop/xshop-theme/template-parts/components/pagination.php
T

42 lines
1.3 KiB
PHP

<?php
/**
* Pagination — archive/search, accessible, RTL-safe.
*
* @package XShop
*/
declare(strict_types=1);
defined('ABSPATH') || exit;
global $wp_query;
$query = $args['query'] ?? $wp_query;
if (!$query instanceof WP_Query) { return; }
if ((int) $query->max_num_pages <= 1) { return; }
$big = 999999999;
$links = paginate_links([
'base' => str_replace((string) $big, '%#%', esc_url(get_pagenum_link((string) $big))),
'format' => '?paged=%#%',
'current' => max(1, (int) get_query_var('paged', 1)),
'total' => (int) $query->max_num_pages,
'prev_text' => is_rtl() ? esc_html__('Next', 'xshop') : esc_html__('Previous', 'xshop'),
'next_text' => is_rtl() ? esc_html__('Previous', 'xshop') : esc_html__('Next', 'xshop'),
'type' => 'array',
'mid_size' => 1,
'end_size' => 1,
]);
if (empty($links) || !is_array($links)) { return; }
?>
<nav class="xshop-pagination" aria-label="<?php esc_attr_e('Pagination', 'xshop'); ?>">
<div class="nav-links">
<?php foreach ($links as $link):
// paginate_links returns escaped HTML; we allow it via wp_kses with minimal allow-list
// but current span vs anchor is already safe. Use wp_kses_post to preserve classes.
echo wp_kses_post($link);
endforeach; ?>
</div>
</nav>