fix(homepage): align shell with zibll and restore post stream
Move header-slider outside main, render fluid zones once, default the latest stream to plain posts by date, and cut dual-render/perf waste so published posts and hero/banner structure match the zibll contract.
This commit is contained in:
1 parent
8be4c5c123
commit
8f19384582
11 files changed
+223
-103
No files matched your search
+105
-50
@@ -38,21 +38,18 @@ if (!function_exists('aksrt_homepage_get_post_types')) {
|
||||
* Homepage latest feed post types.
|
||||
*
|
||||
* Respects the homepage_content_model setting:
|
||||
* - 'post': standard posts only
|
||||
* - 'mixed': posts + resource CPTs (default for existing sites)
|
||||
* - 'post': standard posts only (default)
|
||||
* - 'mixed': posts + resource CPTs (explicit opt-in)
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function aksrt_homepage_get_post_types(): array {
|
||||
// Default: plain posts only (zibll main-query feel). Mixed/resource is opt-in.
|
||||
$content_model = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::homepage_content_model()
|
||||
: 'mixed';
|
||||
: 'post';
|
||||
|
||||
if ($content_model === 'post') {
|
||||
return ['post'];
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_resource_post_types')) {
|
||||
if ($content_model === 'mixed' && function_exists('aksrt_resource_post_types')) {
|
||||
return array_values(array_unique(aksrt_resource_post_types()));
|
||||
}
|
||||
|
||||
@@ -206,7 +203,7 @@ if (!function_exists('aksrt_homepage_get_sort_mode')) {
|
||||
: ['modified', 'date', 'views', 'likes', 'comments', 'favorites', 'downloads', 'rand'];
|
||||
$default_sort = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::homepage_default_sort()
|
||||
: 'modified';
|
||||
: 'date';
|
||||
$override_sort = get_query_var('aksrt_homepage_sort_override');
|
||||
$sort = is_string($override_sort) && $override_sort !== ''
|
||||
? sanitize_key($override_sort)
|
||||
@@ -253,30 +250,44 @@ if (!function_exists('aksrt_homepage_apply_sort_args')) {
|
||||
function aksrt_homepage_apply_sort_args(array $args): array {
|
||||
$sort_mode = aksrt_homepage_get_sort_mode();
|
||||
|
||||
// Meta sorts: keep posts without the meta key via OR NOT EXISTS so lists never collapse empty.
|
||||
$apply_meta_sort = static function (array $args, string $meta_key): array {
|
||||
$args['meta_key'] = $meta_key;
|
||||
$args['orderby'] = [
|
||||
'meta_value_num' => 'DESC',
|
||||
'date' => 'DESC',
|
||||
];
|
||||
$args['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'key' => $meta_key,
|
||||
'compare' => 'EXISTS',
|
||||
],
|
||||
[
|
||||
'key' => $meta_key,
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
];
|
||||
return $args;
|
||||
};
|
||||
|
||||
switch ($sort_mode) {
|
||||
case 'date':
|
||||
$args['orderby'] = 'date';
|
||||
case 'modified':
|
||||
$args['orderby'] = 'modified';
|
||||
$args['order'] = 'DESC';
|
||||
break;
|
||||
case 'downloads':
|
||||
$args['meta_key'] = '_aksrt_res_download_count';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'DESC';
|
||||
$args = $apply_meta_sort($args, '_aksrt_res_download_count');
|
||||
break;
|
||||
case 'views':
|
||||
$args['meta_key'] = 'aksrt_post_views';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'DESC';
|
||||
// Canonical public views key (align hotspot consumers later).
|
||||
$args = $apply_meta_sort($args, 'aksrt_post_views');
|
||||
break;
|
||||
case 'likes':
|
||||
$args['meta_key'] = '_aksrt_like_count';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'DESC';
|
||||
$args = $apply_meta_sort($args, '_aksrt_like_count');
|
||||
break;
|
||||
case 'favorites':
|
||||
$args['meta_key'] = '_aksrt_favorite_count';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'DESC';
|
||||
$args = $apply_meta_sort($args, '_aksrt_favorite_count');
|
||||
break;
|
||||
case 'comments':
|
||||
$args['orderby'] = 'comment_count';
|
||||
@@ -286,9 +297,9 @@ if (!function_exists('aksrt_homepage_apply_sort_args')) {
|
||||
$args['orderby'] = 'rand';
|
||||
unset($args['order']);
|
||||
break;
|
||||
case 'modified':
|
||||
case 'date':
|
||||
default:
|
||||
$args['orderby'] = 'modified';
|
||||
$args['orderby'] = 'date';
|
||||
$args['order'] = 'DESC';
|
||||
break;
|
||||
}
|
||||
@@ -400,11 +411,12 @@ if (!function_exists('aksrt_homepage_get_latest_query')) {
|
||||
$query_args = [
|
||||
'post_type' => aksrt_homepage_get_post_types(),
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => (int) get_option('posts_per_page'),
|
||||
'posts_per_page' => max(1, (int) get_option('posts_per_page')),
|
||||
'paged' => aksrt_homepage_get_current_page(),
|
||||
'ignore_sticky_posts' => false,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'no_found_rows' => false,
|
||||
];
|
||||
|
||||
$exclude_ids = class_exists('AKSRT_Settings')
|
||||
@@ -758,7 +770,8 @@ if (!function_exists('aksrt_homepage_render_posts_grid')) {
|
||||
$query = $query instanceof WP_Query ? $query : aksrt_homepage_get_latest_query();
|
||||
|
||||
if (function_exists('aksrt_render_post_list')) {
|
||||
aksrt_render_post_list($query, ['mode' => 'list', 'context' => 'home'], true);
|
||||
// Panel already provides posts-row.ajaxpager; avoid nested wrapper.
|
||||
aksrt_render_post_list($query, ['mode' => 'list', 'context' => 'home', 'skip_wrapper' => true], true);
|
||||
} else {
|
||||
if (!$query->have_posts()) {
|
||||
echo '<div class="no-results"><p>' . esc_html__('暂无文章', 'aksrt') . '</p></div>';
|
||||
@@ -798,9 +811,51 @@ if (!function_exists('aksrt_homepage_render_section')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide_is_show')) {
|
||||
/**
|
||||
* Whether the header multi-function slider should render (zibll header-slider contract).
|
||||
*/
|
||||
function aksrt_header_slide_is_show(): bool {
|
||||
if (is_admin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match zibll: only first page of the posts index / front page.
|
||||
if (!(is_front_page() || is_home())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_homepage_get_current_page') && aksrt_homepage_get_current_page() > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return function_exists('aksrt_homepage_module_hero_enabled')
|
||||
? aksrt_homepage_module_hero_enabled()
|
||||
: true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide')) {
|
||||
/**
|
||||
* Render header slider after the site header (outside main).
|
||||
*/
|
||||
function aksrt_header_slide(): void {
|
||||
if (!aksrt_header_slide_is_show()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reuse existing hero partial as the slider implementation.
|
||||
get_template_part('templates/parts/home-modules/module', 'hero');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
/**
|
||||
* Render the fixed homepage layout (Zibll latest-first content stream).
|
||||
*
|
||||
* Order (zibll-aligned):
|
||||
* fluid top → main.container → top content → banner → tabs/list → bottom content → sidebar
|
||||
* → 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();
|
||||
@@ -808,25 +863,19 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
$tab_configs = $show_tabs ? aksrt_homepage_get_tab_configs() : [];
|
||||
$latest_contract = aksrt_homepage_get_latest_panel_contract();
|
||||
$has_sidebar = aksrt_homepage_has_sidebar();
|
||||
$hero_on = $show_tabs && aksrt_homepage_module_hero_enabled();
|
||||
$banner_on = $show_tabs && aksrt_homepage_module_banner_enabled();
|
||||
$main_list_enabled = !class_exists('AKSRT_Settings') || AKSRT_Settings::home_posts_list_enabled();
|
||||
$list_title = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::home_list_title()
|
||||
: __('最新发布', 'aksrt');
|
||||
|
||||
// Fluid zones live outside <main>, once only (removed from header.php).
|
||||
aksrt_homepage_render_widget_zone(
|
||||
['all_top_fluid', 'home_top_fluid'],
|
||||
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--top'
|
||||
);
|
||||
?>
|
||||
<main id="main-content" role="main" class="site-main container aksrt-homepage" tabindex="-1">
|
||||
<?php
|
||||
aksrt_homepage_render_widget_zone(
|
||||
['all_top_fluid', 'home_top_fluid'],
|
||||
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--top'
|
||||
);
|
||||
|
||||
if ($hero_on && function_exists('aksrt_homepage_render_section')) {
|
||||
aksrt_homepage_render_section('hero');
|
||||
}
|
||||
?>
|
||||
|
||||
<main id="main-content" role="main" class="container site-main aksrt-homepage" tabindex="-1">
|
||||
<div class="content-wrap aksrt-homepage__shell">
|
||||
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?> aksrt-homepage__content-layout">
|
||||
<div class="content-layout__primary aksrt-homepage__primary">
|
||||
@@ -845,7 +894,7 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
<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="aksrt-homepage__tab-list scroll-x no-scrollbar" role="tablist" data-aksrt-home-tabs style="width:100%;">
|
||||
<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 esc_html($list_title !== '' ? $list_title : __('最新发布', 'aksrt')); ?>
|
||||
@@ -886,7 +935,7 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
<?php aksrt_homepage_render_sortbar(); ?>
|
||||
|
||||
<div class="aksrt-homepage__panels tab-content">
|
||||
<div class="aksrt-homepage__panel posts-row ajaxpager tab-pane is-active" role="tabpanel" data-home-tab-panel="latest" id="index-tab-main">
|
||||
<div class="aksrt-homepage__panel posts-row ajaxpager tab-pane fade in active is-active" role="tabpanel" data-home-tab-panel="latest" id="index-tab-main">
|
||||
<div
|
||||
class="aksrt-homepage__panel-contract"
|
||||
data-query-context="<?php echo esc_attr($latest_contract['query_context']); ?>"
|
||||
@@ -901,7 +950,7 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
<?php if ($show_tabs && !empty($tab_configs)) : ?>
|
||||
<?php foreach ($tab_configs as $tab_cfg) : ?>
|
||||
<div
|
||||
class="aksrt-homepage__panel ajaxpager tab-pane"
|
||||
class="aksrt-homepage__panel posts-row ajaxpager tab-pane"
|
||||
role="tabpanel"
|
||||
data-home-tab-panel="term-<?php echo (int) $tab_cfg['term_id']; ?>"
|
||||
data-tab-orderby="<?php echo esc_attr($tab_cfg['orderby']); ?>"
|
||||
@@ -911,6 +960,15 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
<?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
|
||||
@@ -924,15 +982,12 @@ if (!function_exists('aksrt_homepage_render_layout')) {
|
||||
<?php aksrt_homepage_render_sidebar(); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
aksrt_homepage_render_widget_zone(
|
||||
['home_bottom_fluid', 'all_bottom_fluid'],
|
||||
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--bottom'
|
||||
);
|
||||
?>
|
||||
</main>
|
||||
<?php
|
||||
aksrt_homepage_render_widget_zone(
|
||||
['home_bottom_fluid', 'all_bottom_fluid'],
|
||||
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--bottom'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user