feat(widgets): category-tabs REST mini list and ajax null

Prefer shared mini list for category tab REST fallback and always return
aksrt_get_ajax_null when the panel query is empty.
This commit is contained in:
2026-07-21 11:22:50 +08:00
parent c8f80806d8
commit f34b982ac6
+22 -6
View File
@@ -129,15 +129,31 @@ class WidgetAjax {
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>';
if (function_exists('aksrt_render_mini_list')) {
echo '<div class="widget-tab-posts__list widget-tab-posts__list--mini">';
aksrt_render_mini_list($query, ['context' => 'widget', 'show_thumb' => true]);
echo '</div>';
} else {
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>';
}
echo '</ul>';
} else {
echo function_exists('aksrt_get_ajax_null')
? aksrt_get_ajax_null(__('暂无文章', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
: '<p class="widget-empty ajax-item">' . esc_html__('暂无文章', 'aksrt') . '</p>';
}
wp_reset_postdata();
return new \WP_REST_Response(['success' => true, 'html' => (string) ob_get_clean()], 200);
$html = (string) ob_get_clean();
if ($html === '') {
$html = function_exists('aksrt_get_ajax_null')
? aksrt_get_ajax_null(__('暂无文章', 'aksrt'))
: '<p class="widget-empty ajax-item">' . esc_html__('暂无文章', 'aksrt') . '</p>';
}
return new \WP_REST_Response(['success' => true, 'html' => $html], 200);
}
public function rest_hot_posts(\WP_REST_Request $request) {