对小工具进行了一些修复
This commit is contained in:
@@ -26,15 +26,17 @@ final class PostRenderer {
|
||||
|
||||
public static function items(\WP_Query $query, array $instance, string $slug, int $page = 1): string {
|
||||
if (!$query->have_posts()) {
|
||||
return RendererHelpers::empty_state(__('暂无文章', 'aksrt'));
|
||||
return RendererHelpers::empty_state(__('暂无内容', 'aksrt'));
|
||||
}
|
||||
$style = (string) ($instance['style'] ?? 'card');
|
||||
$mode = in_array($style, ['list', 'card', 'mini'], true) ? $style : 'card';
|
||||
$config = [
|
||||
'type' => $mode === 'card' ? 'card' : 'list',
|
||||
'show_number' => $slug === 'hot_posts',
|
||||
'show_thumb' => $slug !== 'hot_posts' || !array_key_exists('show_thumbnail', $instance) || !empty($instance['show_thumbnail']),
|
||||
'show_meta' => true,
|
||||
'show_number' => $slug === 'hot_posts' || in_array('show_number', (array) ($instance['mini_opt'] ?? []), true),
|
||||
'show_thumb' => $slug === 'tab_posts'
|
||||
? in_array('show_thumb', (array) ($instance['mini_opt'] ?? []), true)
|
||||
: ($slug !== 'hot_posts' || !array_key_exists('show_thumbnail', $instance) || !empty($instance['show_thumbnail'])),
|
||||
'show_meta' => $slug !== 'tab_posts' || in_array('show_meta', (array) ($instance['mini_opt'] ?? []), true),
|
||||
'number_offset' => ($page - 1) * max(1, (int) ($instance['count'] ?? 8)),
|
||||
'wrapper_class' => 'aksrt-widget-posts aksrt-widget-posts--' . $slug,
|
||||
'widget_style' => $mode,
|
||||
@@ -77,11 +79,14 @@ final class PostRenderer {
|
||||
}
|
||||
|
||||
private static function pagination(array $instance, int $page, int $max_pages): string {
|
||||
$mode = (string) ($instance['paginate'] ?? 'none');
|
||||
if ($max_pages <= 1 || $mode === 'none') {
|
||||
$mode = (string) ($instance['paginate'] ?? '');
|
||||
if ($max_pages <= 1) {
|
||||
return '';
|
||||
}
|
||||
if ($mode === 'numbered') {
|
||||
if ($mode === '' || $mode === 'none') {
|
||||
return '<div class="ajax-pag hide"><div class="next-page ajax-next"><a href="#"></a></div></div>';
|
||||
}
|
||||
if ($mode === 'number' || $mode === 'numbered') {
|
||||
$start = max(1, min($page - 2, $max_pages - 4));
|
||||
$end = min($max_pages, max(5, $page + 2));
|
||||
$html = '<nav class="aksrt-widget-pagination" aria-label="' . esc_attr__('文章分页', 'aksrt') . '">';
|
||||
@@ -90,9 +95,9 @@ final class PostRenderer {
|
||||
}
|
||||
return $html . '</nav>';
|
||||
}
|
||||
$label = $mode === 'infinite' ? __('继续加载', 'aksrt') : __('加载更多', 'aksrt');
|
||||
$class = $mode === 'infinite' ? 'aksrt-widget-load-more ias-btn lazyload' : 'aksrt-widget-load-more';
|
||||
$action = $mode === 'infinite' ? ' lazyload-action="ias"' : '';
|
||||
$label = __('加载更多', 'aksrt');
|
||||
$class = 'aksrt-widget-load-more';
|
||||
$action = '';
|
||||
return '<button class="' . $class . '"' . $action . ' type="button" data-next-page="' . (int) ($page + 1) . '" data-mode="' . esc_attr($mode) . '">' . esc_html($label) . '</button>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user