Merge pull request 'Worktree hero banner chain' (#114) from worktree-hero-banner-chain into main

Reviewed-on: CYL/wordpress-theme-aksrt#114
This commit is contained in:
kate522 committed 2026-07-14 00:06:11 +08:00
commit 4e08d997a1
13 files changed
+35 -154

No files matched your search

@@ -379,7 +379,6 @@ const addPresetOptions = computed(() => {
const presets = [ const presets = [
{ label: '写文章', key: 'post' }, { label: '写文章', key: 'post' },
{ label: '投稿页', key: 'submit' }, { label: '投稿页', key: 'submit' },
{ label: '发布资源', key: 'resource' },
{ label: '用户中心创作', key: 'profile' }, { label: '用户中心创作', key: 'profile' },
] ]
@@ -493,7 +492,6 @@ function applyAddPreset(key) {
const presetFactories = { const presetFactories = {
post: () => ({ label: '写文章', icon: 'fas fa-pen-nib', url: `${adminUrl || siteUrl}/post-new.php` }), post: () => ({ label: '写文章', icon: 'fas fa-pen-nib', url: `${adminUrl || siteUrl}/post-new.php` }),
submit: () => ({ label: '投稿页', icon: 'fas fa-paper-plane', url: `${siteUrl}/submit/` }), submit: () => ({ label: '投稿页', icon: 'fas fa-paper-plane', url: `${siteUrl}/submit/` }),
resource: () => ({ label: '发布资源', icon: 'fas fa-box-open', url: `${siteUrl}/resources/` }),
profile: () => ({ label: '创作中心', icon: 'fas fa-user-edit', url: `${siteUrl}/user/` }), profile: () => ({ label: '创作中心', icon: 'fas fa-user-edit', url: `${siteUrl}/user/` }),
} }
@@ -522,7 +520,6 @@ function getAddPresetValue(key) {
const presetFactories = { const presetFactories = {
post: () => ({ label: '写文章', icon: 'fas fa-pen-nib', url: `${adminUrl || siteUrl}/post-new.php` }), post: () => ({ label: '写文章', icon: 'fas fa-pen-nib', url: `${adminUrl || siteUrl}/post-new.php` }),
submit: () => ({ label: '投稿页', icon: 'fas fa-paper-plane', url: `${siteUrl}/submit/` }), submit: () => ({ label: '投稿页', icon: 'fas fa-paper-plane', url: `${siteUrl}/submit/` }),
resource: () => ({ label: '发布资源', icon: 'fas fa-box-open', url: `${siteUrl}/resources/` }),
profile: () => ({ label: '创作中心', icon: 'fas fa-user-edit', url: `${siteUrl}/user/` }), profile: () => ({ label: '创作中心', icon: 'fas fa-user-edit', url: `${siteUrl}/user/` }),
} }
@@ -2,7 +2,7 @@
<div class="aksrt-page-container content-page"> <div class="aksrt-page-container content-page">
<PageHeader <PageHeader
title="首页配置" title="首页配置"
desc="按 Zibll 首页主线配置内容类型、Tab、主列表与基础交互。列表/卡片显示请在「文章列表」中设置。" desc="配置首页主列表、分类 Tab 与基础交互。列表/卡片显示请在「文章列表」中设置。"
> >
<template #actions> <template #actions>
<n-button type="primary" :loading="saving" @click="handleSave">保存设置</n-button> <n-button type="primary" :loading="saving" @click="handleSave">保存设置</n-button>
@@ -13,25 +13,11 @@
<n-tab-pane name="stream" tab="主列表 & Tab"> <n-tab-pane name="stream" tab="主列表 & Tab">
<n-spin :show="loading" style="width:100%; min-height:200px;"> <n-spin :show="loading" style="width:100%; min-height:200px;">
<n-card class="aksrt-section-card" style="margin-bottom:16px;"> <n-card class="aksrt-section-card" style="margin-bottom:16px;">
<template #header><strong>首页内容</strong></template> <template #header><strong>首页说明</strong></template>
<n-form :model="form" label-placement="left" label-width="160" class="aksrt-form"> <n-form :model="form" label-placement="left" label-width="160" class="aksrt-form">
<n-form-item label="首页内容模型"> <n-form-item label="内容说明">
<n-radio-group v-model:value="form.homepage_content_model">
<n-space vertical>
<n-radio value="mixed">
<n-text>混合内容流</n-text>
<n-text depth="3" style="margin-left:8px;">文章 + 资源,贴近 Zibll 首页主流呈现。</n-text>
</n-radio>
<n-radio value="post">
<n-text>纯文章流</n-text>
<n-text depth="3" style="margin-left:8px;">仅标准文章,适合纯资讯站点。</n-text>
</n-radio>
</n-space>
</n-radio-group>
</n-form-item>
<n-form-item label="首页说明">
<n-alert type="info" :show-icon="false"> <n-alert type="info" :show-icon="false">
当前首页已切换为固定骨架模式,不再使用旧版自由模块画布、导入导出预设或历史模块桥接。 首页主列表只使用普通文章。下载/付费是文章能力(meta),不是第二种内容类型。当前为固定骨架模式,不再使用旧版自由模块画布。
</n-alert> </n-alert>
</n-form-item> </n-form-item>
</n-form> </n-form>
@@ -228,7 +214,6 @@ const allSortOptions = [
] ]
const form = reactive({ const form = reactive({
homepage_content_model: 'mixed',
home_posts_list_s: true, home_posts_list_s: true,
home_list1_orderby_s: true, home_list1_orderby_s: true,
home_list1_orderby_option: { home_list1_orderby_option: {
@@ -296,7 +281,6 @@ async function loadSettings() {
const res = await api.getHomepageSettings() const res = await api.getHomepageSettings()
const d = res?.data || {} const d = res?.data || {}
form.homepage_content_model = d.homepage_content_model || 'mixed'
form.home_posts_list_s = d.home_posts_list_s !== false && d.home_posts_list_enabled !== false form.home_posts_list_s = d.home_posts_list_s !== false && d.home_posts_list_enabled !== false
form.home_list1_orderby_s = d.home_list1_orderby_s !== false && d.home_list_sort_enabled !== false form.home_list1_orderby_s = d.home_list1_orderby_s !== false && d.home_list_sort_enabled !== false
const orderOpt = d.home_list1_orderby_option && typeof d.home_list1_orderby_option === 'object' ? d.home_list1_orderby_option : {} const orderOpt = d.home_list1_orderby_option && typeof d.home_list1_orderby_option === 'object' ? d.home_list1_orderby_option : {}
@@ -929,9 +929,8 @@ export const pageDisplaySchemas = {
key: 'page_display.homepage', key: 'page_display.homepage',
title: '首页配置', title: '首页配置',
icon: 'fas fa-home', icon: 'fas fa-home',
description: '配置首页内容模型、主列表、分类 Tab、卡片样式与首页交互。实际编辑界面在 HomepageSettings.vue(customPage),此处补齐 page_display 的 schema 契约。', description: '配置首页主列表、分类 Tab、卡片样式与首页交互。实际编辑界面在 HomepageSettings.vue(customPage),此处补齐 page_display 的 schema 契约。',
defaults: { defaults: {
homepage_content_model: 'post',
homepage_tabs: [], homepage_tabs: [],
homepage_card_style: 'default', homepage_card_style: 'default',
homepage_multi_thumb_enabled: false, homepage_multi_thumb_enabled: false,
@@ -952,24 +951,6 @@ export const pageDisplaySchemas = {
homepage_tab_limit: 4, homepage_tab_limit: 4,
}, },
groups: [ groups: [
{
key: 'content-model',
title: '内容模型',
icon: 'fas fa-stream',
fields: [
{
key: 'homepage_content_model',
label: '首页内容模型',
type: 'radio',
default: 'post',
options: [
{ label: '混合模式', value: 'mixed' },
{ label: '纯文章', value: 'post' },
],
help: '混合模式显示文章 + 资源,纯文章模式仅显示标准文章。',
},
],
},
{ {
key: 'main-stream', key: 'main-stream',
title: '主列表', title: '主列表',
+10 -31
View File
@@ -109,8 +109,8 @@ export const MODULE_LIBRARY = [
type: 'ranking', type: 'ranking',
label: '排行榜', label: '排行榜',
icon: 'trophy', icon: 'trophy',
desc: '按下载量 / 阅读量 / 评论数排序', desc: '按下载量 / 阅读量 / 评论数排序(普通文章)',
defaultConfig: { metric: 'downloads', count: 6, post_type: 'resource', title: '' }, defaultConfig: { metric: 'downloads', count: 6, title: '' },
fields: [ fields: [
{ key: 'title', type: 'text', label: '标题' }, { key: 'title', type: 'text', label: '标题' },
{ {
@@ -121,31 +121,17 @@ export const MODULE_LIBRARY = [
{ label: '评论数', value: 'comments' }, { label: '评论数', value: 'comments' },
], ],
}, },
{
key: 'post_type', type: 'select', label: '内容类型',
options: [
{ label: '资源', value: 'resource' },
{ label: '文章', value: 'post' },
],
},
{ key: 'count', type: 'number', label: '数量', min: 1, max: 20 }, { key: 'count', type: 'number', label: '数量', min: 1, max: 20 },
], ],
}, },
{ {
type: 'recent', type: 'recent',
label: '最新内容', label: '最新文章',
icon: 'clock', icon: 'clock',
desc: '按时间倒序的最新文章 / 资源', desc: '按时间倒序的最新文章',
defaultConfig: { post_type: 'post', count: 6, layout: 'card', title: '' }, defaultConfig: { count: 6, layout: 'card', title: '' },
fields: [ fields: [
{ key: 'title', type: 'text', label: '标题' }, { key: 'title', type: 'text', label: '标题' },
{
key: 'post_type', type: 'select', label: '内容类型',
options: [
{ label: '文章', value: 'post' },
{ label: '资源', value: 'resource' },
],
},
{ key: 'count', type: 'number', label: '数量', min: 1, max: 20 }, { key: 'count', type: 'number', label: '数量', min: 1, max: 20 },
{ {
key: 'layout', type: 'select', label: '布局', key: 'layout', type: 'select', label: '布局',
@@ -196,7 +182,7 @@ export const MODULE_LIBRARY = [
label: '热点推荐', label: '热点推荐',
icon: 'fire', icon: 'fire',
desc: '文章推荐列表(纯文本,仅桌面端显示)', desc: '文章推荐列表(纯文本,仅桌面端显示)',
defaultConfig: { count: 6, post_type: 'post', source: 'auto', title: '' }, defaultConfig: { count: 6, source: 'auto', title: '' },
fields: [ fields: [
{ key: 'title', type: 'text', label: '标题' }, { key: 'title', type: 'text', label: '标题' },
{ key: 'count', type: 'number', label: '数量', min: 3, max: 20 }, { key: 'count', type: 'number', label: '数量', min: 3, max: 20 },
@@ -208,13 +194,6 @@ export const MODULE_LIBRARY = [
{ label: '最热文章(按阅读量)', value: 'views' }, { label: '最热文章(按阅读量)', value: 'views' },
], ],
}, },
{
key: 'post_type', type: 'select', label: '内容类型',
options: [
{ label: '文章', value: 'post' },
{ label: '资源', value: 'resource' },
],
},
], ],
}, },
{ {
@@ -478,12 +457,12 @@ export const PRESET_TEMPLATES = [
{ {
key: 'resource_standard', key: 'resource_standard',
label: '资源站标准', label: '资源站标准',
desc: 'Hero(固定骨架)+ Tabs + 最新资源 + 下载排行', desc: 'Hero(固定骨架)+ Tabs + 最新文章 + 下载排行',
modules: [ modules: [
{ type: 'hero', config: {} }, { type: 'hero', config: {} },
{ type: 'tabs', config: { count: 8, layout: 'grid-cms' } }, { type: 'tabs', config: { count: 8, layout: 'grid-cms' } },
{ type: 'recent', config: { post_type: 'resource', count: 8, layout: 'grid-cms' } }, { type: 'recent', config: { count: 8, layout: 'grid-cms' } },
{ type: 'ranking', config: { metric: 'downloads', post_type: 'resource', count: 6 } }, { type: 'ranking', config: { metric: 'downloads', count: 6 } },
], ],
}, },
{ {
@@ -503,7 +482,7 @@ export const PRESET_TEMPLATES = [
desc: 'Hero(固定骨架)+ 最新文章 + 多个分类块', desc: 'Hero(固定骨架)+ 最新文章 + 多个分类块',
modules: [ modules: [
{ type: 'hero', config: {} }, { type: 'hero', config: {} },
{ type: 'recent', config: { post_type: 'post', count: 6, layout: 'card' } }, { type: 'recent', config: { count: 6, layout: 'card' } },
{ type: 'category', config: { count: 6, columns: 3, layout: 'card' } }, { type: 'category', config: { count: 6, columns: 3, layout: 'card' } },
{ type: 'category', config: { count: 6, columns: 3, layout: 'card' } }, { type: 'category', config: { count: 6, columns: 3, layout: 'card' } },
], ],
@@ -126,11 +126,6 @@ trait AKSRT_Admin_Homepage_Settings_Rest {
if (array_key_exists('homepage_sticky_tabs_enabled', $params)) { if (array_key_exists('homepage_sticky_tabs_enabled', $params)) {
$settings['homepage_sticky_tabs_enabled'] = !empty($params['homepage_sticky_tabs_enabled']); $settings['homepage_sticky_tabs_enabled'] = !empty($params['homepage_sticky_tabs_enabled']);
} }
if (isset($params['homepage_content_model'])) {
$settings['homepage_content_model'] = in_array($params['homepage_content_model'], ['post', 'mixed'], true)
? $params['homepage_content_model']
: 'mixed';
}
if (array_key_exists('home_list_sort_dropdown', $params)) { if (array_key_exists('home_list_sort_dropdown', $params)) {
$settings['home_list_sort_dropdown'] = !empty($params['home_list_sort_dropdown']); $settings['home_list_sort_dropdown'] = !empty($params['home_list_sort_dropdown']);
} }
+3 -3
View File
@@ -215,7 +215,7 @@ class AKSRT_Home_Modules {
case 'mixed': case 'mixed':
return [ return [
['type' => 'hero', 'config' => []], ['type' => 'hero', 'config' => []],
['type' => 'recent', 'config' => ['post_type' => 'post', 'count' => 6, 'layout' => 'card']], ['type' => 'recent', 'config' => ['count' => 6, 'layout' => 'card']],
['type' => 'category', 'config' => ['count' => 6, 'columns' => 3]], ['type' => 'category', 'config' => ['count' => 6, 'columns' => 3]],
['type' => 'category', 'config' => ['count' => 6, 'columns' => 3]], ['type' => 'category', 'config' => ['count' => 6, 'columns' => 3]],
]; ];
@@ -225,8 +225,8 @@ class AKSRT_Home_Modules {
return [ return [
['type' => 'hero', 'config' => []], ['type' => 'hero', 'config' => []],
['type' => 'tabs', 'config' => ['count' => 8]], ['type' => 'tabs', 'config' => ['count' => 8]],
['type' => 'recent', 'config' => ['post_type' => 'resource', 'count' => 8, 'layout' => 'grid-cms']], ['type' => 'recent', 'config' => ['count' => 8, 'layout' => 'grid-cms']],
['type' => 'ranking', 'config' => ['metric' => 'downloads', 'count' => 6, 'post_type' => 'resource']], ['type' => 'ranking', 'config' => ['metric' => 'downloads', 'count' => 6]],
]; ];
} }
} }
@@ -1205,7 +1205,6 @@ trait AKSRT_Scripts_Part_1b {
'homepageDefaultView' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_default_view() : 'list', 'homepageDefaultView' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_default_view() : 'list',
'homepageSortAjax' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_sort_ajax_enabled() : true, 'homepageSortAjax' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_sort_ajax_enabled() : true,
'homepageStickyTabs' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_sticky_tabs_enabled() : true, 'homepageStickyTabs' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_sticky_tabs_enabled() : true,
'homepageContentModel' => class_exists('AKSRT_Settings') ? AKSRT_Settings::homepage_content_model() : 'mixed',
'homePostsListEnabled' => !class_exists('AKSRT_Settings') || AKSRT_Settings::home_posts_list_enabled(), 'homePostsListEnabled' => !class_exists('AKSRT_Settings') || AKSRT_Settings::home_posts_list_enabled(),
'homeListSortEnabled' => !class_exists('AKSRT_Settings') || AKSRT_Settings::home_list_sort_enabled(), 'homeListSortEnabled' => !class_exists('AKSRT_Settings') || AKSRT_Settings::home_list_sort_enabled(),
'homeListSortDropdown' => class_exists('AKSRT_Settings') && AKSRT_Settings::home_list_sort_dropdown(), 'homeListSortDropdown' => class_exists('AKSRT_Settings') && AKSRT_Settings::home_list_sort_dropdown(),
@@ -255,7 +255,6 @@ class AKSRT_Settings_Home_Cms {
'homepage_default_view' => isset($s['homepage_default_view']) ? sanitize_key((string) $s['homepage_default_view']) : 'list', 'homepage_default_view' => isset($s['homepage_default_view']) ? sanitize_key((string) $s['homepage_default_view']) : 'list',
'homepage_sort_ajax_enabled' => !isset($s['homepage_sort_ajax_enabled']) || !empty($s['homepage_sort_ajax_enabled']), 'homepage_sort_ajax_enabled' => !isset($s['homepage_sort_ajax_enabled']) || !empty($s['homepage_sort_ajax_enabled']),
'homepage_sticky_tabs_enabled' => !isset($s['homepage_sticky_tabs_enabled']) || !empty($s['homepage_sticky_tabs_enabled']), 'homepage_sticky_tabs_enabled' => !isset($s['homepage_sticky_tabs_enabled']) || !empty($s['homepage_sticky_tabs_enabled']),
'homepage_content_model' => isset($s['homepage_content_model']) && in_array($s['homepage_content_model'], ['post', 'mixed'], true) ? $s['homepage_content_model'] : 'post',
'home_list_sort_dropdown' => !empty($s['home_list_sort_dropdown']), 'home_list_sort_dropdown' => !empty($s['home_list_sort_dropdown']),
'homepage_tab_posts_per_page' => max(1, min(20, (int) ($s['homepage_tab_posts_per_page'] ?? 6))), 'homepage_tab_posts_per_page' => max(1, min(20, (int) ($s['homepage_tab_posts_per_page'] ?? 6))),
'homepage_tab_limit' => max(1, min(12, (int) ($s['homepage_tab_limit'] ?? 4))), 'homepage_tab_limit' => max(1, min(12, (int) ($s['homepage_tab_limit'] ?? 4))),
@@ -276,9 +275,13 @@ class AKSRT_Settings_Home_Cms {
return $settings; return $settings;
} }
/**
* Homepage always uses ordinary posts. Kept for API stability.
*
* @return string Always 'post'.
*/
public static function homepage_content_model(): string { public static function homepage_content_model(): string {
$settings = self::get_homepage_fixed_settings(); return 'post';
return $settings['homepage_content_model'];
} }
public static function homepage_tabs(): array { public static function homepage_tabs(): array {
@@ -31,9 +31,9 @@ trait AKSRT_Settings_Homepage_Reader {
} }
/** /**
* Homepage content model. * Homepage always uses ordinary posts.
* *
* @return string 'post' or 'mixed' * @return string Always 'post'.
*/ */
public static function homepage_content_model(): string { public static function homepage_content_model(): string {
return AKSRT_Settings_Home_Cms::homepage_content_model(); return AKSRT_Settings_Home_Cms::homepage_content_model();
-13
View File
@@ -443,19 +443,6 @@ if (!function_exists('aksrt_is_resource_archive')) {
} }
} }
/**
* Normalize homepage-module content scope.
* Values: post | resource (resource = posts marked _aksrt_is_resource).
*/
if (!function_exists('aksrt_normalize_content_scope')) {
function aksrt_normalize_content_scope($scope): string {
$scope = sanitize_key((string) $scope);
if ($scope === 'resource') {
return 'resource';
}
return 'post';
}
}
if (!function_exists('aksrt_detect_cloud_service')) { if (!function_exists('aksrt_detect_cloud_service')) {
/** /**
@@ -3,7 +3,7 @@
* Home Module · Hotspot 热点推荐 * Home Module · Hotspot 热点推荐
* *
* 纯文章列表(无图片),仅桌面端显示。 * 纯文章列表(无图片),仅桌面端显示。
* config: { count, post_type: 'post'|'resource', source, title? } * config: { count, source, title? }
* *
* source: * source:
* 'auto' → 优先读取 aksrt_recommend meta,不足时用最新补充 * 'auto' → 优先读取 aksrt_recommend meta,不足时用最新补充
@@ -18,9 +18,6 @@ if (!is_array($cfg)) {
} }
$count = max(3, min(20, (int) ($cfg['count'] ?? 6))); $count = max(3, min(20, (int) ($cfg['count'] ?? 6)));
$scope = function_exists('aksrt_normalize_content_scope')
? aksrt_normalize_content_scope($cfg['post_type'] ?? 'post')
: 'post';
$source = (string) ($cfg['source'] ?? 'auto'); $source = (string) ($cfg['source'] ?? 'auto');
$title = (string) ($cfg['title'] ?? ''); $title = (string) ($cfg['title'] ?? '');
@@ -28,8 +25,6 @@ if (!in_array($source, ['auto', 'recent', 'views'], true)) {
$source = 'auto'; $source = 'auto';
} }
$is_resource = $scope === 'resource';
$args = [ $args = [
'post_type' => 'post', 'post_type' => 'post',
'posts_per_page' => $count, 'posts_per_page' => $count,
@@ -37,15 +32,8 @@ $args = [
'no_found_rows' => true, 'no_found_rows' => true,
]; ];
$meta_query = [];
if ($is_resource) {
$meta_query[] = function_exists('aksrt_resource_meta_query')
? aksrt_resource_meta_query()
: ['key' => '_aksrt_is_resource', 'value' => '1', 'compare' => '='];
}
if ($source === 'auto') { if ($source === 'auto') {
$meta_query[] = [ $args['meta_query'] = [
'relation' => 'OR', 'relation' => 'OR',
['key' => 'aksrt_recommend', 'value' => '1', 'compare' => '='], ['key' => 'aksrt_recommend', 'value' => '1', 'compare' => '='],
['key' => 'aksrt_recommend', 'compare' => 'NOT EXISTS'], ['key' => 'aksrt_recommend', 'compare' => 'NOT EXISTS'],
@@ -61,20 +49,13 @@ if ($source === 'auto') {
$args['order'] = 'DESC'; $args['order'] = 'DESC';
} }
if (count($meta_query) === 1) {
$args['meta_query'] = $meta_query;
} elseif (count($meta_query) > 1) {
$args['meta_query'] = array_merge(['relation' => 'AND'], $meta_query);
}
$query = new WP_Query($args); $query = new WP_Query($args);
if (!$query->have_posts()) { if (!$query->have_posts()) {
wp_reset_postdata(); wp_reset_postdata();
return; return;
} }
$default_title = __('热点推荐', 'aksrt'); $display_title = $title ?: __('热点推荐', 'aksrt');
$display_title = $title ?: $default_title;
?> ?>
<section class="home-module home-module--hotspot hotspot--desktop-only" aria-label="<?php echo esc_attr($display_title); ?>"> <section class="home-module home-module--hotspot hotspot--desktop-only" aria-label="<?php echo esc_attr($display_title); ?>">
@@ -2,7 +2,8 @@
/** /**
* Home Module · Ranking * Home Module · Ranking
* *
* config: { metric: 'views|downloads|comments', count, post_type: 'post'|'resource', title? } * config: { metric: 'views|downloads|comments', count, title? }
* Lists ordinary posts only (no content-type split).
*/ */
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@@ -13,30 +14,18 @@ if (!is_array($cfg)) {
$metric = (string) ($cfg['metric'] ?? 'downloads'); $metric = (string) ($cfg['metric'] ?? 'downloads');
$count = max(1, min(20, (int) ($cfg['count'] ?? 6))); $count = max(1, min(20, (int) ($cfg['count'] ?? 6)));
$scope = function_exists('aksrt_normalize_content_scope')
? aksrt_normalize_content_scope($cfg['post_type'] ?? 'resource')
: 'resource';
$title = (string) ($cfg['title'] ?? ''); $title = (string) ($cfg['title'] ?? '');
if (!in_array($metric, ['views', 'downloads', 'comments'], true)) { if (!in_array($metric, ['views', 'downloads', 'comments'], true)) {
$metric = 'downloads'; $metric = 'downloads';
} }
$is_resource_module = $scope === 'resource';
$args = [ $args = [
'post_type' => 'post', 'post_type' => 'post',
'posts_per_page' => $count, 'posts_per_page' => $count,
'post_status' => 'publish', 'post_status' => 'publish',
'no_found_rows' => true, 'no_found_rows' => true,
]; ];
if ($is_resource_module) {
$args['meta_query'] = [
function_exists('aksrt_resource_meta_query')
? aksrt_resource_meta_query()
: ['key' => '_aksrt_is_resource', 'value' => '1', 'compare' => '='],
];
}
switch ($metric) { switch ($metric) {
case 'views': case 'views':
+4 -18
View File
@@ -2,7 +2,8 @@
/** /**
* Home Module · Recent * Home Module · Recent
* *
* config: { post_type: 'post'|'resource', count, layout, title? } * config: { count, layout, title? }
* Lists ordinary posts only (no content-type split).
*/ */
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@@ -11,9 +12,6 @@ if (!is_array($cfg)) {
$cfg = []; $cfg = [];
} }
$scope = function_exists('aksrt_normalize_content_scope')
? aksrt_normalize_content_scope($cfg['post_type'] ?? 'post')
: ((string) ($cfg['post_type'] ?? 'post') === 'resource' ? 'resource' : 'post');
$count = max(1, min(20, (int) ($cfg['count'] ?? 6))); $count = max(1, min(20, (int) ($cfg['count'] ?? 6)));
$layout = (string) ($cfg['layout'] ?? 'card'); $layout = (string) ($cfg['layout'] ?? 'card');
$title = (string) ($cfg['title'] ?? ''); $title = (string) ($cfg['title'] ?? '');
@@ -22,8 +20,6 @@ if (!in_array($layout, ['card', 'list', 'masonry', 'grid-cms'], true)) {
$layout = 'card'; $layout = 'card';
} }
$is_resource_module = $scope === 'resource';
$args = [ $args = [
'post_type' => 'post', 'post_type' => 'post',
'posts_per_page' => $count, 'posts_per_page' => $count,
@@ -32,13 +28,6 @@ $args = [
'orderby' => 'date', 'orderby' => 'date',
'order' => 'DESC', 'order' => 'DESC',
]; ];
if ($is_resource_module) {
$args['meta_query'] = [
function_exists('aksrt_resource_meta_query')
? aksrt_resource_meta_query()
: ['key' => '_aksrt_is_resource', 'value' => '1', 'compare' => '='],
];
}
$query = new WP_Query($args); $query = new WP_Query($args);
if (!$query->have_posts()) { if (!$query->have_posts()) {
@@ -46,11 +35,8 @@ if (!$query->have_posts()) {
return; return;
} }
$default_title = $is_resource_module ? __('最新资源', 'aksrt') : __('最新文章', 'aksrt'); $display_title = $title ?: __('最新文章', 'aksrt');
$display_title = $title ?: $default_title; $archive_link = get_permalink(get_option('page_for_posts'));
$archive_link = $is_resource_module
? (function_exists('aksrt_resource_archive_url') ? aksrt_resource_archive_url() : home_url('/resources/'))
: get_permalink(get_option('page_for_posts'));
?> ?>
<section class="home-module home-module--recent container" aria-label="<?php echo esc_attr($display_title); ?>"> <section class="home-module home-module--recent container" aria-label="<?php echo esc_attr($display_title); ?>">