feat(widgets): number paginate + main/tab query depth
Add shared aksrt_get_ajax_number_paginate, MainPosts topics/pay_type/ favorites filters and number pager, TabPosts style/paginate/skeleton payload, REST wiring, product number AJAX parity.
This commit is contained in:
@@ -109,3 +109,83 @@ if (!function_exists('aksrt_get_remote_modal_link')) {
|
||||
return '<' . $tag . $attrs . '>' . esc_html($text) . '</' . $tag . '>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_ajax_number_paginate')) {
|
||||
/**
|
||||
* Numbered AJAX pager (zibll zib_get_ajax_number_paginate subset).
|
||||
*
|
||||
* Links use class next-page ajax-next + ajax-replace so ajax-list.js
|
||||
* replaces .ajax-item rows inside the nearest .ajaxpager.
|
||||
*
|
||||
* @param int $count_all Total items.
|
||||
* @param int $page Current page (1-based).
|
||||
* @param int $per_page Per page.
|
||||
* @param string $ajax_url Base REST/URL (page query key replaced).
|
||||
* @param string $pag_class Wrapper class.
|
||||
* @param string $next_class Link base class.
|
||||
* @param string $query_key Page query arg (default page).
|
||||
*/
|
||||
function aksrt_get_ajax_number_paginate(
|
||||
int $count_all,
|
||||
int $page = 1,
|
||||
int $per_page = 10,
|
||||
string $ajax_url = '',
|
||||
string $pag_class = 'ajax-pag',
|
||||
string $next_class = 'next-page ajax-next',
|
||||
string $query_key = 'page'
|
||||
): string {
|
||||
$page = max(1, $page);
|
||||
$per_page = max(1, $per_page);
|
||||
$total_pages = (int) ceil(max(0, $count_all) / $per_page);
|
||||
if ($total_pages < 2 || $count_all <= 0) {
|
||||
return '<div class="' . esc_attr($pag_class) . ' hide"><div class="' . esc_attr($next_class) . '"><a href="#"></a></div></div>';
|
||||
}
|
||||
|
||||
$base = $ajax_url !== '' ? $ajax_url : '#';
|
||||
// Ensure %#% placeholder for page numbers.
|
||||
if (strpos($base, '%#%') === false) {
|
||||
$base = add_query_arg($query_key, '%#%', $base);
|
||||
}
|
||||
|
||||
$end_size = 1;
|
||||
$mid_size = 2;
|
||||
$links = [];
|
||||
$dots = false;
|
||||
|
||||
// Prev.
|
||||
if ($page > 1) {
|
||||
$url = esc_url(str_replace('%#%', (string) ($page - 1), $base));
|
||||
$links[] = '<a class="' . esc_attr($next_class) . ' prev page-numbers" ajax-replace="true" href="' . $url . '"><i class="fa fa-angle-left em12" aria-hidden="true"></i></a>';
|
||||
}
|
||||
|
||||
for ($n = 1; $n <= $total_pages; $n++) {
|
||||
$in_window = $n <= $end_size
|
||||
|| $n > $total_pages - $end_size
|
||||
|| ($n >= $page - $mid_size && $n <= $page + $mid_size);
|
||||
if (!$in_window) {
|
||||
if ($dots) {
|
||||
continue;
|
||||
}
|
||||
$links[] = '<span class="page-numbers dots">…</span>';
|
||||
$dots = true;
|
||||
continue;
|
||||
}
|
||||
$dots = false;
|
||||
if ($n === $page) {
|
||||
$links[] = '<span class="page-numbers current">' . (int) $n . '</span>';
|
||||
} else {
|
||||
$url = esc_url(str_replace('%#%', (string) $n, $base));
|
||||
$links[] = '<a class="' . esc_attr($next_class) . ' page-numbers" ajax-replace="true" href="' . $url . '">' . (int) $n . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// Next.
|
||||
if ($page < $total_pages) {
|
||||
$url = esc_url(str_replace('%#%', (string) ($page + 1), $base));
|
||||
$links[] = '<a class="' . esc_attr($next_class) . ' next page-numbers" ajax-replace="true" href="' . $url . '"><i class="fa fa-angle-right em12" aria-hidden="true"></i></a>';
|
||||
}
|
||||
|
||||
return '<div class="pagenav ' . esc_attr($pag_class) . '">' . implode('', $links) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user