fix 更多栏目

This commit is contained in:
kate522 committed 2026-09-05 17:32:18 +08:00
1 parent 5b89fc200b
commit 05a6b6fc54
28 files changed
+440 -2295

No files matched your search

+111 -85
View File
@@ -16,15 +16,7 @@ if (!function_exists('aksrt_homepage_render_layout')) {
* → fluid bottom. Hero/header-slider is rendered from header.php, not here.
*/
function aksrt_homepage_render_layout(): void {
$current_page = aksrt_homepage_get_current_page();
$show_tabs = $current_page === 1;
$tab_configs = $show_tabs ? aksrt_homepage_get_tab_configs() : [];
$latest_contract = aksrt_homepage_get_latest_panel_contract();
$view_mode = (($latest_contract['render_config_array']['mode'] ?? 'list') === 'card') ? 'card' : 'list';
$main_list_enabled = !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::home_posts_list_enabled();
$list_title = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_list_title()
: __('最新发布', 'aksrt');
// Fluid zones live outside <main>, once only (removed from header.php).
aksrt_homepage_render_widget_zone(
@@ -43,86 +35,19 @@ if (!function_exists('aksrt_homepage_render_layout')) {
?>
<?php if ($main_list_enabled) : ?>
<section class="aksrt-homepage__stream home-tab-content" aria-label="<?php esc_attr_e('Homepage Content', 'aksrt'); ?>">
<?php if ($show_tabs && !empty($tab_configs)) : ?>
<div class="index-tab affix-header-sm relative home-tab-nav-box aksrt-homepage__tabs mb10" data-sticky-tabs="<?php echo aksrt_homepage_sticky_tabs_enabled() ? 'true' : 'false'; ?>" offset-top="-8">
<ul class="list-inline scroll-x no-scrollbar aksrt-homepage__tab-list" role="tablist" data-aksrt-home-tabs style="width:100%;">
<li class="aksrt-homepage__tab-item is-active" role="presentation">
<button type="button" class="aksrt-homepage__tab-button" role="tab" aria-selected="true" data-home-tab-target="latest">
<?php echo wp_kses_post($list_title !== '' ? $list_title : __('最新发布', 'aksrt')); ?>
</button>
</li>
<?php foreach ($tab_configs as $tab_cfg) : ?>
<li class="aksrt-homepage__tab-item" role="presentation">
<button
type="button"
class="aksrt-homepage__tab-button"
role="tab"
aria-selected="false"
data-home-tab-target="term-<?php echo (int) $tab_cfg['term_id']; ?>"
data-tab-orderby="<?php echo esc_attr($tab_cfg['orderby']); ?>"
>
<?php echo wp_kses_post($tab_cfg['title']); ?>
</button>
</li>
<?php endforeach; ?>
</ul>
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/homepage', __('首页设置', 'aksrt'), 'aksrt-admin-quicklink aksrt-homepage__admin-link'); } ?>
</div>
<?php elseif ($current_page > 1) : ?>
<div class="box-body notop nobottom aksrt-homepage__titlebox">
<div class="title-theme">
<?php echo wp_kses_post($list_title !== '' ? $list_title : __('最新发布', 'aksrt')); ?>
<small class="aksrt-homepage__page-indicator ml10">
<?php echo esc_html(sprintf(__('第 %d 页', 'aksrt'), $current_page)); ?>
</small>
<?php if ($main_list_enabled) :
$tab_configs = aksrt_homepage_get_current_page() === 1 ? aksrt_homepage_get_tab_configs() : [];
?>
<div class="home-tab-content">
<?php echo aksrt_homepage_get_tab_header_html($tab_configs); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="tab-content">
<div class="posts-row ajaxpager tab-pane fade in active" id="index-tab-main">
<?php aksrt_homepage_render_ajax_option_menu(); ?>
<?php aksrt_homepage_render_posts_grid(aksrt_homepage_get_latest_query(), true); ?>
</div>
<?php echo aksrt_homepage_get_tab_panes_html($tab_configs); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<?php elseif ($list_title !== '') : ?>
<div class="box-body notop nobottom aksrt-homepage__titlebox">
<div class="title-theme"><?php echo wp_kses_post($list_title); ?></div>
</div>
<?php endif; ?>
<?php aksrt_homepage_render_sortbar(); ?>
<div class="aksrt-homepage__panels tab-content">
<div class="aksrt-homepage__panel aksrt-homepage__posts posts-row post-grid post-grid--home ajaxpager tab-pane is-active show" role="tabpanel" data-home-tab-panel="latest" data-view="<?php echo esc_attr($view_mode); ?>" id="index-tab-main">
<div
class="aksrt-homepage__panel-contract"
data-query-context="<?php echo esc_attr($latest_contract['query_context']); ?>"
data-query-vars="<?php echo esc_attr($latest_contract['query_vars']); ?>"
data-render-config="<?php echo esc_attr($latest_contract['render_config']); ?>"
data-page="1"
data-tab="latest"
></div>
<?php aksrt_homepage_render_posts_grid(aksrt_homepage_get_latest_query(), true); ?>
</div>
<?php if ($show_tabs && !empty($tab_configs)) : ?>
<?php foreach ($tab_configs as $tab_cfg) : ?>
<div
class="aksrt-homepage__panel aksrt-homepage__posts posts-row post-grid post-grid--home ajaxpager tab-pane"
data-view="<?php echo esc_attr($view_mode); ?>"
role="tabpanel"
data-home-tab-panel="term-<?php echo (int) $tab_cfg['term_id']; ?>"
data-tab-orderby="<?php echo esc_attr($tab_cfg['orderby']); ?>"
hidden
></div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
<?php else : ?>
<section class="aksrt-homepage__stream home-tab-content aksrt-homepage__stream--disabled" aria-label="<?php esc_attr_e('Homepage Content', 'aksrt'); ?>">
<div class="no-results box-body">
<p><?php esc_html_e('首页主列表已关闭。', 'aksrt'); ?></p>
<?php if (current_user_can('manage_options') && function_exists('aksrt_render_admin_quick_link')) : ?>
<?php aksrt_render_admin_quick_link('page-display/homepage', __('打开首页设置并启用主列表', 'aksrt'), 'aksrt-admin-quicklink'); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
<?php
@@ -144,6 +69,107 @@ if (!function_exists('aksrt_homepage_render_layout')) {
}
}
if (!function_exists('aksrt_homepage_get_tab_header_html')) {
/**
* legacy zib_index_tab_html:tab 导航 / 翻页标题条 / 空占位 三态。
*
* @param array<int, array<string, mixed>> $tab_configs Configured term tabs.
*/
function aksrt_homepage_get_tab_header_html(array $tab_configs): string {
$list_title = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_list_title()
: '';
$fallback_title = $list_title !== '' ? $list_title : __('最新发布', 'aksrt');
$paged = aksrt_homepage_get_current_page();
//不是第一页
if ($paged > 1) {
return '<div class="box-body notop nobottom"><div class="title-theme">' . $fallback_title
. '<small class="ml10">' . esc_html(sprintf(__('第%s页', 'aksrt'), $paged)) . '</small></div></div>';
}
$index_tab_nav = '';
foreach ($tab_configs as $index => $tab_cfg) {
$index_tab_nav .= '<li><a data-toggle="tab" data-ajax="' . esc_url(aksrt_homepage_get_tab_link($tab_cfg))
. '" href="#index-tab-' . (int) $index . '">' . wp_kses_post($tab_cfg['title']) . '</a></li>';
}
if (!$index_tab_nav) {
return $list_title !== ''
? '<div class="box-body notop nobottom"><div class="title-theme">' . wp_kses_post($list_title) . '</div></div>'
: '<div></div>';
}
$html = '<li class="active"><a data-toggle="tab" href="#index-tab-main">' . wp_kses_post($fallback_title) . '</a></li>' . $index_tab_nav;
return '<div class="index-tab affix-header-sm relative home-tab-nav-box mb10" offset-top="-8"><ul style="width:100%;" class="scroll-x no-scrollbar">' . $html . '</ul></div>';
}
}
if (!function_exists('aksrt_homepage_get_tab_panes_html')) {
/**
* legacy zib_index_tab('content'):每个栏目的原位刷新 pane。
*
* pane 本身就是 .ajaxpager;post_ajax_trigger 指向栏目页,post_ajax 加载后
* 用栏目页自身的列表 DOM 原地替换 loader,不新建区域。
*
* @param array<int, array<string, mixed>> $tab_configs Configured term tabs.
*/
function aksrt_homepage_get_tab_panes_html(array $tab_configs): string {
if (!$tab_configs) {
return '';
}
$is_card = class_exists('\AKSRT\Settings\PostDisplay')
&& \AKSRT\Settings\PostDisplay::get_archive_layout() === 'card';
$is_mobel = wp_is_mobile();
if ($is_card) {
$placeholder_type = 'card';
$placeholder_num = $is_mobel ? 4 : 12;
} else {
$placeholder_type = 'list';
$placeholder_num = $is_mobel ? 4 : 6;
}
$placeholder = aksrt_render_placeholder($placeholder_type, $placeholder_num);
$html = '';
foreach ($tab_configs as $index => $tab_cfg) {
$html .= '<div class="ajaxpager tab-pane fade" id="index-tab-' . (int) $index . '">';
$html .= '<span class="post_ajax_trigger"><a class="ajax_load ajax-next ajax-open" href="' . esc_url(aksrt_homepage_get_tab_link($tab_cfg)) . '"></a></span>';
$html .= '<div class="post_ajax_loader">' . $placeholder . '</div>';
$html .= '</div>';
}
return $html;
}
}
if (!function_exists('aksrt_homepage_get_tab_link')) {
/**
* 栏目 tab 的加载链接:栏目页 + nofilter(抑制响应页的筛选菜单)。
*
* @param array<string, mixed> $tab_cfg Tab config with term and orderby.
*/
function aksrt_homepage_get_tab_link(array $tab_cfg): string {
$term = $tab_cfg['term'] ?? null;
if (!$term instanceof WP_Term) {
return home_url('/');
}
$query_arg = ['nofilter' => 'true'];
if (!empty($tab_cfg['orderby'])) {
$query_arg['orderby'] = $tab_cfg['orderby'];
}
$link = get_term_link($term);
if (is_wp_error($link)) {
return home_url('/');
}
return add_query_arg($query_arg, $link);
}
}
if (!function_exists('aksrt_render_fixed_homepage')) {
/**
* Render the new fixed homepage layout.