feat(widgets): category tabs lazy load + ranking extras
SSR first category panel; remaining tabs fetch grid HTML via /widgets/category-tabs. User ranking adds zibll-like desc modes.
This commit is contained in:
1 parent
d508a9aef8
commit
90d84af2f5
3 files changed
+175
-21
No files matched your search
@@ -39,6 +39,11 @@ class WidgetAjax {
|
||||
'callback' => [$this, 'rest_paid_posts'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
register_rest_route('aksrt/v1', '/widgets/category-tabs', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'rest_category_tabs'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
}
|
||||
|
||||
public function rest_main_posts(\WP_REST_Request $request) {
|
||||
@@ -116,4 +121,38 @@ class WidgetAjax {
|
||||
'total' => (int) ($payload['total'] ?? 0),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function rest_category_tabs(\WP_REST_Request $request) {
|
||||
$cat = max(0, (int) ($request->get_param('cat') ?? 0));
|
||||
$count = max(1, min(12, (int) ($request->get_param('count') ?? 6)));
|
||||
$layout = sanitize_key((string) ($request->get_param('layout') ?? 'card'));
|
||||
$columns = max(1, min(4, (int) ($request->get_param('columns') ?? 3)));
|
||||
$context = sanitize_key((string) ($request->get_param('context') ?? 'homepage'));
|
||||
if ($cat <= 0) {
|
||||
return new \WP_REST_Response(['success' => true, 'html' => ''], 200);
|
||||
}
|
||||
$post_types = function_exists('aksrt_home_widget_post_types') ? aksrt_home_widget_post_types() : ['post'];
|
||||
$query = new \WP_Query([
|
||||
'post_type' => $post_types,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => $count,
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'cat' => $cat,
|
||||
]);
|
||||
ob_start();
|
||||
if (function_exists('aksrt_home_widget_render_post_grid')) {
|
||||
aksrt_home_widget_render_post_grid($query, $layout, $columns, $context);
|
||||
} elseif ($query->have_posts()) {
|
||||
echo '<ul class="widget-tab-posts__list">';
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
echo '<li><a href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
wp_reset_postdata();
|
||||
$html = (string) ob_get_clean();
|
||||
return new \WP_REST_Response(['success' => true, 'html' => $html], 200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user