fix(list): wire Zibll list/card display chain end-to-end
Resolve post list mode from global list_type + surface card overrides so homepage/archives/AJAX honor admin list and card style settings.
This commit is contained in:
1 parent
b2815614d1
commit
d73a7af25e
17 files changed
+444
-151
No files matched your search
@@ -301,13 +301,20 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
|
||||
|
||||
$query = new WP_Query($args);
|
||||
|
||||
$mode = in_array($view_mode, ['card', 'list'], true) ? $view_mode : 'list';
|
||||
$mode = in_array($view_mode, ['card', 'list'], true) ? $view_mode : '';
|
||||
$html = '';
|
||||
if (function_exists('aksrt_render_post_list')) {
|
||||
$html = aksrt_render_post_list($query, [
|
||||
'mode' => $mode,
|
||||
'context' => 'home',
|
||||
], false);
|
||||
$overrides = ['context' => 'home'];
|
||||
if ($mode !== '') {
|
||||
$overrides['mode'] = $mode;
|
||||
}
|
||||
$render_config = function_exists('aksrt_resolve_post_list_render_config')
|
||||
? aksrt_resolve_post_list_render_config([
|
||||
'context' => 'home',
|
||||
'overrides' => $overrides,
|
||||
])
|
||||
: array_merge(['mode' => ($mode !== '' ? $mode : 'list'), 'context' => 'home'], $overrides);
|
||||
$html = aksrt_render_post_list($query, $render_config, false);
|
||||
} elseif ($query->have_posts()) {
|
||||
$html = '<div class="posts-row aksrt-homepage__posts" data-view="' . esc_attr($mode) . '">';
|
||||
while ($query->have_posts()) {
|
||||
|
||||
@@ -159,16 +159,16 @@ class AKSRT_Admin_Schema_Post_List_List {
|
||||
'fields' => [
|
||||
[
|
||||
'key' => 'post_card_style',
|
||||
'label' => '列表卡片样式',
|
||||
'label' => '默认列表模式',
|
||||
'type' => 'select',
|
||||
'default' => 'thumb',
|
||||
'options' => [
|
||||
['label' => '标准图文', 'value' => 'thumb'],
|
||||
['label' => '列表图文模式', 'value' => 'thumb'],
|
||||
['label' => '紧凑卡', 'value' => 'compact'],
|
||||
['label' => '大图卡', 'value' => 'large_thumb'],
|
||||
['label' => '多图卡', 'value' => 'multi_thumb'],
|
||||
['label' => '纯文字', 'value' => 'text'],
|
||||
['label' => '有图则图文', 'value' => 'thumb_if_has'],
|
||||
['label' => '列表文字模式', 'value' => 'text'],
|
||||
['label' => '列表自动图文', 'value' => 'thumb_if_has'],
|
||||
['label' => '卡片模式', 'value' => 'card'],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -226,7 +226,10 @@ class AKSRT_Admin {
|
||||
public static function sanitize_public_render_config(array $config): array {
|
||||
$clean = [];
|
||||
if (isset($config['mode'])) {
|
||||
$clean['mode'] = sanitize_key((string) $config['mode']);
|
||||
$mode = sanitize_key((string) $config['mode']);
|
||||
if (in_array($mode, ['list', 'card', 'mini', 'grid-cms'], true)) {
|
||||
$clean['mode'] = $mode;
|
||||
}
|
||||
}
|
||||
if (isset($config['context'])) {
|
||||
$clean['context'] = sanitize_key((string) $config['context']);
|
||||
@@ -234,9 +237,49 @@ class AKSRT_Admin {
|
||||
if (isset($config['query_context'])) {
|
||||
$clean['query_context'] = sanitize_key((string) $config['query_context']);
|
||||
}
|
||||
if (isset($config['style'])) {
|
||||
$style = sanitize_key((string) $config['style']);
|
||||
if (in_array($style, ['', 'style2', 'style3'], true)) {
|
||||
$clean['style'] = $style;
|
||||
}
|
||||
}
|
||||
if (isset($config['card_style'])) {
|
||||
$card_style = sanitize_key((string) $config['card_style']);
|
||||
$allowed = ['thumb', 'text', 'thumb_if_has', 'card', 'compact', 'large_thumb', 'multi_thumb', 'standard'];
|
||||
if (in_array($card_style, $allowed, true)) {
|
||||
$clean['card_style'] = $card_style;
|
||||
}
|
||||
}
|
||||
if (isset($config['list_show_type'])) {
|
||||
$v = sanitize_key((string) $config['list_show_type']);
|
||||
if (in_array($v, ['separate', 'no_margin'], true)) {
|
||||
$clean['list_show_type'] = $v;
|
||||
}
|
||||
}
|
||||
if (isset($config['list_img_position'])) {
|
||||
$v = sanitize_key((string) $config['list_img_position']);
|
||||
if (in_array($v, ['left', 'right'], true)) {
|
||||
$clean['list_img_position'] = $v;
|
||||
}
|
||||
}
|
||||
foreach (['thumb_if_has', 'show_thumb', 'show_author', 'show_date', 'show_views', 'show_comments', 'show_likes', 'show_excerpt', 'heading_bold', 'target_blank', 'badge_show', 'multi_thumb_enabled', 'skip_wrapper'] as $bool_key) {
|
||||
if (array_key_exists($bool_key, $config)) {
|
||||
$clean[$bool_key] = !empty($config[$bool_key]);
|
||||
}
|
||||
}
|
||||
if (isset($config['multi_thumb_limit'])) {
|
||||
$clean['multi_thumb_limit'] = max(1, min(6, (int) $config['multi_thumb_limit']));
|
||||
}
|
||||
if (isset($config['multi_thumb_min'])) {
|
||||
$clean['multi_thumb_min'] = max(1, min(6, (int) $config['multi_thumb_min']));
|
||||
}
|
||||
if (isset($config['excerpt_words'])) {
|
||||
$clean['excerpt_words'] = max(0, min(200, (int) $config['excerpt_words']));
|
||||
}
|
||||
return $clean;
|
||||
}
|
||||
|
||||
|
||||
public function ajax_load_more_posts(): void {
|
||||
check_ajax_referer('aksrt_public_nonce', 'nonce');
|
||||
$page = max(1, (int) ($_POST['page'] ?? 1));
|
||||
@@ -244,6 +287,18 @@ class AKSRT_Admin {
|
||||
$render_config = json_decode(wp_unslash((string) ($_POST['render_config'] ?? '{}')), true);
|
||||
$query_vars = is_array($query_vars) ? self::sanitize_public_query_vars($query_vars) : [];
|
||||
$render_config = is_array($render_config) ? self::sanitize_public_render_config($render_config) : [];
|
||||
// Prefer server-side resolution so AJAX matches SSR styles even if client config is slim.
|
||||
if (function_exists('aksrt_resolve_post_list_render_config')) {
|
||||
$context = sanitize_key((string) ($render_config['context'] ?? 'archive'));
|
||||
if ($context === '') {
|
||||
$context = 'archive';
|
||||
}
|
||||
$resolved = aksrt_resolve_post_list_render_config([
|
||||
'context' => $context,
|
||||
'overrides' => $render_config,
|
||||
]);
|
||||
$render_config = array_merge($resolved, $render_config);
|
||||
}
|
||||
$query_vars['paged'] = $page;
|
||||
|
||||
$query = new WP_Query($query_vars);
|
||||
|
||||
@@ -84,19 +84,24 @@ class AKSRT_Term_Meta {
|
||||
$saved = [];
|
||||
}
|
||||
|
||||
$layout_mode = isset($saved['layout_mode']) && $saved['layout_mode'] !== ''
|
||||
? sanitize_key((string) $saved['layout_mode'])
|
||||
: (string) ($global['list_mode'] ?? 'grid');
|
||||
|
||||
$layout_map = [
|
||||
'grid' => ['mode' => 'card', 'card_style' => 'standard'],
|
||||
'card' => ['mode' => 'card', 'card_style' => 'standard'],
|
||||
'list' => ['mode' => 'list', 'card_style' => 'standard'],
|
||||
'compact' => ['mode' => 'list', 'card_style' => 'compact'],
|
||||
'mini' => ['mode' => 'mini', 'card_style' => 'standard'],
|
||||
'grid-cms' => ['mode' => 'grid-cms', 'card_style' => 'standard'],
|
||||
];
|
||||
$resolved_layout = $layout_map[$layout_mode] ?? ['mode' => 'card', 'card_style' => 'standard'];
|
||||
// Empty term layout_mode means follow global post-list settings (Zibll).
|
||||
// Do not fall back to page-display list_mode=grid which forced card everywhere.
|
||||
$layout_preset = isset($saved['layout_mode']) ? sanitize_key((string) $saved['layout_mode']) : '';
|
||||
if ($layout_preset === '') {
|
||||
$resolved_layout = ['mode' => '', 'card_style' => ''];
|
||||
$layout_mode = '';
|
||||
} else {
|
||||
$layout_mode = $layout_preset;
|
||||
$layout_map = [
|
||||
'grid' => ['mode' => 'card', 'card_style' => 'thumb'],
|
||||
'card' => ['mode' => 'card', 'card_style' => 'thumb'],
|
||||
'list' => ['mode' => 'list', 'card_style' => 'thumb'],
|
||||
'compact' => ['mode' => 'list', 'card_style' => 'compact'],
|
||||
'mini' => ['mode' => 'mini', 'card_style' => 'thumb'],
|
||||
'grid-cms' => ['mode' => 'grid-cms', 'card_style' => 'thumb'],
|
||||
];
|
||||
$resolved_layout = $layout_map[$layout_mode] ?? ['mode' => 'list', 'card_style' => 'thumb'];
|
||||
}
|
||||
|
||||
$header_style = (string) ($global['header_style'] ?? 'simple');
|
||||
if (!in_array($header_style, ['cover', 'simple', 'none'], true)) {
|
||||
|
||||
@@ -161,7 +161,7 @@ trait AKSRT_Settings_Display_Page_Groups {
|
||||
|
||||
return [
|
||||
'list' => [
|
||||
'post_card_style' => $list['card_style'],
|
||||
'post_card_style' => $list['list_type'] ?? $list['card_style'] ?? 'thumb',
|
||||
'post_list_author' => $list['show_author'],
|
||||
'post_show_date' => $list['show_date'],
|
||||
'post_show_views' => $list['show_views'],
|
||||
@@ -188,10 +188,10 @@ trait AKSRT_Settings_Display_Page_Groups {
|
||||
'list_list_style' => $list['list_style'],
|
||||
'list_list_img_position' => $list['list_img_position'],
|
||||
'list_list_scale' => $list['list_scale'],
|
||||
'list_card_style' => $list['card_style'],
|
||||
'list_card_style' => $list['card_variant'] ?? '',
|
||||
'list_card_scale' => $list['card_scale'],
|
||||
'list_card_home' => $list['card_home'],
|
||||
'list_card_cat' => $list['card_cat'],
|
||||
'list_card_cat' => $list['card_cat_ids'] ?? [],
|
||||
'list_card_tag' => $list['card_tag'],
|
||||
'list_card_topics' => $list['card_topics'],
|
||||
'list_card_author' => $list['card_author'],
|
||||
|
||||
@@ -11,19 +11,26 @@ class AKSRT_Settings_Post_Display {
|
||||
|
||||
public static function get_post_list_style_settings(): array {
|
||||
$settings = AKSRT_Settings::get_all();
|
||||
$card_style = sanitize_key((string) ($settings['post_card_style'] ?? 'thumb'));
|
||||
$allowed_styles = ['thumb', 'compact', 'large_thumb', 'multi_thumb', 'text', 'thumb_if_has', 'card', 'standard'];
|
||||
|
||||
if (!in_array($card_style, $allowed_styles, true)) {
|
||||
$card_style = 'thumb';
|
||||
// post_card_style storage key mirrors Zibll list_type.
|
||||
$list_type = sanitize_key((string) ($settings['post_card_style'] ?? 'thumb'));
|
||||
$allowed_list_types = ['thumb', 'compact', 'large_thumb', 'multi_thumb', 'text', 'thumb_if_has', 'card', 'standard'];
|
||||
|
||||
if (!in_array($list_type, $allowed_list_types, true)) {
|
||||
$list_type = 'thumb';
|
||||
}
|
||||
// historical alias
|
||||
if ($card_style === 'standard') {
|
||||
$card_style = 'thumb';
|
||||
// Historical aliases → Zibll list_type tokens.
|
||||
if ($list_type === 'standard') {
|
||||
$list_type = 'thumb';
|
||||
}
|
||||
// Non-Zibll extras stay list-mode variants (never force card grid).
|
||||
if (in_array($list_type, ['compact', 'large_thumb', 'multi_thumb'], true)) {
|
||||
// Keep token for CSS hooks; render as list.
|
||||
}
|
||||
|
||||
// Zibll: only list_type=card is card mode; thumb/text/thumb_if_has are list.
|
||||
$render_mode_map = [
|
||||
'thumb' => 'card',
|
||||
'thumb' => 'list',
|
||||
'compact' => 'list',
|
||||
'large_thumb' => 'list',
|
||||
'multi_thumb' => 'list',
|
||||
@@ -74,9 +81,34 @@ class AKSRT_Settings_Post_Display {
|
||||
$ajax_nomore = sanitize_text_field((string) $settings['ajax_nomore_text']);
|
||||
}
|
||||
|
||||
$list_style = sanitize_key((string) ($settings['list_list_style'] ?? ''));
|
||||
if (!in_array($list_style, ['', 'style2'], true)) {
|
||||
$list_style = '';
|
||||
}
|
||||
|
||||
$card_variant = sanitize_key((string) ($settings['list_card_style'] ?? ''));
|
||||
if (!in_array($card_variant, ['', 'style3'], true)) {
|
||||
$card_variant = '';
|
||||
}
|
||||
|
||||
$card_cat_ids = [];
|
||||
if (is_array($settings['list_card_cat'] ?? null)) {
|
||||
$card_cat_ids = array_values(array_filter(array_map('intval', $settings['list_card_cat'])));
|
||||
}
|
||||
|
||||
return [
|
||||
'card_style' => in_array(sanitize_key((string) ($settings['list_card_style'] ?? '')), ['', 'style3'], true) ? sanitize_key((string) ($settings['list_card_style'] ?? '')) : '',
|
||||
'render_mode' => $render_mode_map[$card_style] ?? 'card',
|
||||
// Zibll list_type (storage: post_card_style).
|
||||
'list_type' => $list_type,
|
||||
// Base mode from list_type only (surface card overrides applied by resolver).
|
||||
'render_mode' => $render_mode_map[$list_type] ?? 'list',
|
||||
// List item subtype token for text/thumb_if_has class hooks (not card variant).
|
||||
'list_type_token' => $list_type,
|
||||
// List mode visual variant (Zibll list_list_option.style).
|
||||
'list_style' => $list_style,
|
||||
// Card mode visual variant (Zibll list_card_option.style).
|
||||
'card_variant' => $card_variant,
|
||||
// Back-compat aliases used by older callers (prefer list_type / card_variant).
|
||||
'card_style' => $list_type,
|
||||
'show_author' => $show_author,
|
||||
'show_date' => $show_date,
|
||||
'show_views' => !isset($settings['post_show_views']) || !empty($settings['post_show_views']),
|
||||
@@ -100,13 +132,12 @@ class AKSRT_Settings_Post_Display {
|
||||
'list_orderby' => in_array(sanitize_key((string) ($settings['list_orderby'] ?? 'modified')), ['modified', 'date', 'default'], true) ? sanitize_key((string) ($settings['list_orderby'] ?? 'modified')) : 'modified',
|
||||
'columns' => max(1, min(3, (int) ($settings['post_list_columns'] ?? 1))),
|
||||
'per_page' => max(4, min(48, (int) ($settings['post_list_per_page'] ?? 12))),
|
||||
'list_style' => in_array(sanitize_key((string) ($settings['list_list_style'] ?? '')), ['', 'style2'], true) ? sanitize_key((string) ($settings['list_list_style'] ?? '')) : '',
|
||||
'list_img_position' => in_array(sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')), ['left', 'right'], true) ? sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')) : 'left',
|
||||
'list_scale' => max(50, min(200, (int) ($settings['list_list_scale'] ?? 70))),
|
||||
'card_scale' => max(20, min(200, (int) ($settings['list_card_scale'] ?? 70))),
|
||||
'card_home' => !empty($settings['list_card_home']),
|
||||
'card_cat' => !empty($settings['list_card_cat']),
|
||||
'card_cat_ids' => is_array($settings['list_card_cat'] ?? null) ? array_map('intval', $settings['list_card_cat']) : [],
|
||||
'card_cat' => !empty($card_cat_ids),
|
||||
'card_cat_ids' => $card_cat_ids,
|
||||
'card_tag' => !empty($settings['list_card_tag']),
|
||||
'card_topics' => !empty($settings['list_card_topics']),
|
||||
'card_author' => !empty($settings['list_card_author']),
|
||||
|
||||
Reference in new issue
Block a user