fix 更多栏目
This commit is contained in:
1 parent
5b89fc200b
commit
05a6b6fc54
28 files changed
+440
-2295
No files matched your search
@@ -187,6 +187,11 @@ if (!function_exists('aksrt_archive_render_filter_bar')) :
|
||||
* @param array<string,mixed> $args Filter bar args.
|
||||
*/
|
||||
function aksrt_archive_render_filter_bar(array $args = []): void {
|
||||
// legacy zib_ajax_option_menu:nofilter 请求(首页更多栏目 tab 加载)不输出筛选菜单。
|
||||
if (!empty($_GET['nofilter'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = wp_parse_args($args, [
|
||||
'ajax' => false,
|
||||
'ajax_archive' => '',
|
||||
|
||||
@@ -217,16 +217,20 @@ if (!function_exists('aksrt_archive_render_stream')) :
|
||||
|
||||
<?php if ($has_posts) : ?>
|
||||
<?php
|
||||
aksrt_render_post_list(array_merge($render_config, ['wrapper_class' => 'content-stream__list']), $query);
|
||||
// legacy 契约:分页渲染在 .ajaxpager 内部(zib_paging 位置),
|
||||
// 首页更多栏目 tab 的 runtime post_ajax 依赖它提取下一页。
|
||||
ob_start();
|
||||
aksrt_render_pagination($query, [
|
||||
'query_context' => (string) $args['query_context'],
|
||||
'render_config' => $render_config,
|
||||
]);
|
||||
$pagination_html = (string) ob_get_clean();
|
||||
|
||||
aksrt_render_post_list(array_merge($render_config, [
|
||||
'wrapper_class' => 'content-stream__list',
|
||||
'append_inner_html' => $pagination_html,
|
||||
]), $query);
|
||||
?>
|
||||
<div class="content-stream__footer">
|
||||
<?php
|
||||
aksrt_render_pagination($query, [
|
||||
'query_context' => (string) $args['query_context'],
|
||||
'render_config' => $render_config,
|
||||
]);
|
||||
?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="no-results content-stream__empty">
|
||||
<p><?php echo esc_html((string) $args['empty_text']); ?></p>
|
||||
|
||||
+127
-107
@@ -46,7 +46,7 @@ if (!function_exists('aksrt_homepage_get_post_types')) {
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_tab_terms')) {
|
||||
if (!function_exists('aksrt_homepage_get_tab_configs')) {
|
||||
/**
|
||||
* Homepage category tabs with full config.
|
||||
*
|
||||
@@ -88,52 +88,12 @@ if (!function_exists('aksrt_homepage_get_tab_terms')) {
|
||||
'term' => $term,
|
||||
'term_id' => (int) $tab['term_id'],
|
||||
'title' => $tab['title'] !== '' ? $tab['title'] : $term->name,
|
||||
'orderby' => $tab['orderby'] ?: 'modified',
|
||||
'orderby' => $tab['orderby'] ?: '',
|
||||
];
|
||||
}
|
||||
|
||||
return $configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Homepage category tabs — returns WP_Term objects for backward compat.
|
||||
*
|
||||
* @param int $limit Unused, reads from settings.
|
||||
* @return WP_Term[]
|
||||
*/
|
||||
function aksrt_homepage_get_tab_terms(int $limit = 4): array {
|
||||
$configs = aksrt_homepage_get_tab_configs();
|
||||
return array_column($configs, 'term');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_tab_posts_per_page')) {
|
||||
/**
|
||||
* Per-tab homepage post count.
|
||||
*/
|
||||
function aksrt_homepage_get_tab_posts_per_page(): int {
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$count = \AKSRT\Settings\Settings::homepage_tab_posts_per_page();
|
||||
if ($count > 0) {
|
||||
return max(1, min(20, $count));
|
||||
}
|
||||
}
|
||||
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_sticky_tabs_enabled')) {
|
||||
/**
|
||||
* Whether homepage tabs should stick below the primary nav.
|
||||
*/
|
||||
function aksrt_homepage_sticky_tabs_enabled(): bool {
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
return \AKSRT\Settings\Settings::homepage_sticky_tabs_enabled();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_sort_mode')) {
|
||||
@@ -156,32 +116,23 @@ if (!function_exists('aksrt_homepage_get_sort_mode')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_sort_items')) {
|
||||
if (!function_exists('aksrt_homepage_get_request_sort')) {
|
||||
/**
|
||||
* Configured sort bar items for the main stream.
|
||||
* Main-stream sort requested by URL (?orderby=), legacy zib_sift_posts_per_orde.
|
||||
*
|
||||
* @return array<string,string>
|
||||
* 排序菜单(.ajax-option)点击后原位刷新的响应页靠它同序。
|
||||
*/
|
||||
function aksrt_homepage_get_sort_items(): array {
|
||||
$all_labels = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_sort_labels()
|
||||
: [
|
||||
'modified' => '更新', 'date' => '发布', 'views' => '浏览',
|
||||
'like' => '点赞', 'comment_count' => '评论', 'favorite' => '收藏', 'rand' => '随机',
|
||||
];
|
||||
|
||||
$enabled_keys = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::home_list_sort_options()
|
||||
: array_keys($all_labels);
|
||||
|
||||
$items = [];
|
||||
foreach ($enabled_keys as $key) {
|
||||
if (isset($all_labels[$key])) {
|
||||
$items[$key] = $all_labels[$key];
|
||||
}
|
||||
function aksrt_homepage_get_request_sort(): string {
|
||||
$get_sort = isset($_GET['orderby']) ? sanitize_key(wp_unslash((string) $_GET['orderby'])) : '';
|
||||
if ($get_sort === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return !empty($items) ? $items : ['modified' => '更新', 'date' => '发布'];
|
||||
$allowed = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
|
||||
: ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
|
||||
|
||||
return in_array($get_sort, $allowed, true) ? $get_sort : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,55 +220,124 @@ if (!function_exists('aksrt_homepage_apply_named_sort_args')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_render_sortbar')) {
|
||||
if (!function_exists('aksrt_homepage_render_ajax_option_menu')) {
|
||||
/**
|
||||
* Render the main-stream sort bar.
|
||||
* 首页排序菜单,1:1 zib_ajax_option_menu('home')。
|
||||
*
|
||||
* 输出 .ajax-option.ajax-replace[win-ajax-replace="filter"],点击 .ajax-next
|
||||
* 排序链接由 runtime post_ajax 原位替换 #index-tab-main 内的列表。
|
||||
*/
|
||||
function aksrt_homepage_render_sortbar(): void {
|
||||
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::home_list_sort_enabled()) {
|
||||
function aksrt_homepage_render_ajax_option_menu(): void {
|
||||
if (!empty($_GET['nofilter'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = aksrt_homepage_get_sort_mode();
|
||||
$is_dropdown = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::home_list_sort_dropdown()
|
||||
: false;
|
||||
$sort_items = aksrt_homepage_get_sort_items();
|
||||
$all_labels = class_exists('\AKSRT\Settings\Settings')
|
||||
if (!class_exists('\AKSRT\Settings\Settings') || !\AKSRT\Settings\Settings::home_list_sort_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$con = aksrt_homepage_get_option_orderby_but([
|
||||
'lists' => (array) \AKSRT\Settings\Settings::home_list_sort_options(),
|
||||
'dropdown' => (bool) \AKSRT\Settings\Settings::home_list_sort_dropdown(),
|
||||
]);
|
||||
|
||||
if (!$con) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="ajax-option ajax-replace" win-ajax-replace="filter">' . $con . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div></div>'; // 空白内容,解决css奇数偶数行
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_option_orderby_but')) {
|
||||
/**
|
||||
* 排序方式按钮组,1:1 zib_get_option_orderby_but。
|
||||
*
|
||||
* @param array{lists?:string[],dropdown?:bool} $option Sort option config.
|
||||
*/
|
||||
function aksrt_homepage_get_option_orderby_but($option = []): string {
|
||||
$defaults = [
|
||||
'lists' => [],
|
||||
'dropdown' => false,
|
||||
];
|
||||
|
||||
$option = wp_parse_args((array) $option, $defaults);
|
||||
if (!$option['lists'] && !$option['dropdown']) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$labels = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_sort_labels()
|
||||
: $sort_items;
|
||||
?>
|
||||
<div class="aksrt-homepage__sortbar" aria-label="<?php esc_attr_e('Homepage Sort', 'aksrt'); ?>">
|
||||
<?php if ($is_dropdown) : ?>
|
||||
<div class="aksrt-homepage__sortbar-dropdown">
|
||||
<button type="button" class="aksrt-homepage__sortbar-current" data-sort-dropdown-trigger>
|
||||
<?php echo esc_html($all_labels[$current] ?? $current); ?>
|
||||
<i class="fa fas fa-caret-down" aria-hidden="true"></i>
|
||||
</button>
|
||||
<div class="aksrt-homepage__sortbar-dropdown-menu" hidden>
|
||||
<?php foreach ($sort_items as $sort_key => $label) : ?>
|
||||
<button type="button"
|
||||
class="aksrt-homepage__sortbar-dropdown-item<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
|
||||
data-sort="<?php echo esc_attr($sort_key); ?>"
|
||||
>
|
||||
<?php echo esc_html($label); ?>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="aksrt-homepage__sortbar-links">
|
||||
<?php foreach ($sort_items as $sort_key => $label) : ?>
|
||||
<button type="button"
|
||||
class="aksrt-homepage__sortbar-link<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
|
||||
data-sort="<?php echo esc_attr($sort_key); ?>"
|
||||
>
|
||||
<?php echo esc_html($label); ?>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
: ['modified' => '更新', 'date' => '发布', 'views' => '浏览', 'like' => '点赞', 'comment_count' => '评论', 'favorite' => '收藏', 'rand' => '随机'];
|
||||
|
||||
$dropdown_but = '';
|
||||
$but = '';
|
||||
$uri = aksrt_homepage_url_del_paged(aksrt_homepage_get_current_url());
|
||||
|
||||
foreach ($option['lists'] as $key) {
|
||||
if (!isset($labels[$key])) {
|
||||
continue;
|
||||
}
|
||||
$_class = 'ajax-next';
|
||||
if (isset($_GET['orderby']) && sanitize_key(wp_unslash((string) $_GET['orderby'])) === $key) {
|
||||
$_class .= ' focus-color';
|
||||
}
|
||||
$href = add_query_arg(['orderby' => $key], $uri);
|
||||
$but .= '<a rel="nofollow" ajax-replace="true" class="' . esc_attr($_class) . '" href="' . esc_url($href) . '">' . esc_html($labels[$key]) . '</a>';
|
||||
}
|
||||
if ($option['dropdown']) {
|
||||
foreach ($labels as $key => $value) {
|
||||
$_class = 'ajax-next';
|
||||
if (isset($_GET['orderby']) && sanitize_key(wp_unslash((string) $_GET['orderby'])) === $key) {
|
||||
$_class .= ' focus-color';
|
||||
}
|
||||
$href = add_query_arg(['orderby' => $key], $uri);
|
||||
$dropdown_but .= '<li><a rel="nofollow" ajax-replace="true" class="' . esc_attr($_class) . '" href="' . esc_url($href) . '">' . esc_html($value) . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$but && !$dropdown_but) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$is_dropdown = ($option['dropdown'] && $dropdown_but) ? true : false;
|
||||
$d_but = $is_dropdown
|
||||
? '<a href="javascript:;" data-toggle="dropdown"><span name="cat">' . esc_html__('排序', 'aksrt') . '</span><i class="fa fa-fw fa-sort opacity5" aria-hidden="true"></i></a>'
|
||||
: esc_html__('排序', 'aksrt');
|
||||
|
||||
$html = '<div class="flex ac">';
|
||||
$html .= '<div class="option-dropdown splitters-this-r dropdown flex0">';
|
||||
$html .= $d_but;
|
||||
$html .= $is_dropdown ? '<ul class="dropdown-menu">' . $dropdown_but . '</ul>' : '';
|
||||
$html .= '</div>';
|
||||
$html .= '<ul class="list-inline scroll-x mini-scrollbar option-items">' . $but . '</ul>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_get_current_url')) {
|
||||
/**
|
||||
* 当前页面链接,1:1 zib_get_current_url。
|
||||
*/
|
||||
function aksrt_homepage_get_current_url(): string {
|
||||
$home_url = home_url();
|
||||
$host = preg_replace('/^(http|https)(:\/\/)(?)([^\/]+).*$/im', '$1$2$3', $home_url);
|
||||
|
||||
return $host . add_query_arg(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_homepage_url_del_paged')) {
|
||||
/**
|
||||
* 移除分页参数的链接,1:1 zib_url_del_paged。
|
||||
*/
|
||||
function aksrt_homepage_url_del_paged(string $url): string {
|
||||
$url = remove_query_arg(['paged', 'page'], $url);
|
||||
global $wp_rewrite;
|
||||
|
||||
return preg_replace('/\/' . $wp_rewrite->pagination_base . '\/\d*/', '', $url);
|
||||
}
|
||||
}
|
||||
@@ -43,60 +43,15 @@ if (!function_exists('aksrt_homepage_get_latest_query')) {
|
||||
$query_args['category__not_in'] = $exclude_cat_ids;
|
||||
}
|
||||
|
||||
$query = new WP_Query(aksrt_homepage_apply_sort_args($query_args));
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
if (!function_exists('aksrt_homepage_get_tab_query')) {
|
||||
/**
|
||||
* Build a category-tab query.
|
||||
*/
|
||||
function aksrt_homepage_get_tab_query(int $term_id, string $orderby = 'date'): WP_Query {
|
||||
static $queries = [];
|
||||
|
||||
$cache_key = $term_id . '_' . $orderby;
|
||||
if (isset($queries[$cache_key]) && $queries[$cache_key] instanceof WP_Query) {
|
||||
return $queries[$cache_key];
|
||||
}
|
||||
|
||||
$term = get_term($term_id);
|
||||
$taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category';
|
||||
if ($taxonomy !== 'category') {
|
||||
$taxonomy = 'category';
|
||||
}
|
||||
|
||||
$query_args = [
|
||||
'post_type' => aksrt_homepage_get_post_types(),
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_tab_posts_per_page()
|
||||
: 6,
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'no_found_rows' => true,
|
||||
'tax_query' => [
|
||||
[
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'term_id',
|
||||
'terms' => [$term_id],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$exclude_ids = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::home_exclude_post_ids()
|
||||
: [];
|
||||
if (!empty($exclude_ids)) {
|
||||
$query_args['post__not_in'] = $exclude_ids;
|
||||
}
|
||||
|
||||
$queries[$cache_key] = new WP_Query(
|
||||
aksrt_homepage_apply_named_sort_args($query_args, $orderby)
|
||||
// legacy zib_sift_posts_per_orde:排序菜单的 ?orderby= 优先于后台默认排序。
|
||||
$request_sort = aksrt_homepage_get_request_sort();
|
||||
$query = new WP_Query(
|
||||
$request_sort !== ''
|
||||
? aksrt_homepage_apply_named_sort_args($query_args, $request_sort)
|
||||
: aksrt_homepage_apply_sort_args($query_args)
|
||||
);
|
||||
|
||||
return $queries[$cache_key];
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
if (!function_exists('aksrt_homepage_has_active_sidebars')) {
|
||||
|
||||
+111
-85
@@ -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.
|
||||
|
||||
@@ -152,6 +152,8 @@ if (!function_exists('aksrt_render_post_list')) {
|
||||
$classes[] = $class;
|
||||
}
|
||||
}
|
||||
// legacy 契约:分页等控件与列表同处一个 .ajaxpager 内,供 runtime post_ajax 提取。
|
||||
$append_inner_html = (string) ($cfg['append_inner_html'] ?? '');
|
||||
$html = empty($cfg['skip_wrapper'])
|
||||
? '<div class="' . esc_attr(implode(' ', array_unique($classes))) . '" data-view="' . esc_attr((string) $cfg['mode']) . '">'
|
||||
: '';
|
||||
@@ -168,6 +170,7 @@ if (!function_exists('aksrt_render_post_list')) {
|
||||
$html .= aksrt_render_post($cfg);
|
||||
}
|
||||
}
|
||||
$html .= $append_inner_html;
|
||||
if (empty($cfg['skip_wrapper'])) {
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user