refactor(resource): drop aksrt_resource CPT residue, post+meta only

This commit is contained in:
kate522 committed 2026-07-13 23:47:04 +08:00
1 parent 24c135aeec
commit 1af0e9b753
22 files changed
+362 -986

No files matched your search

+20 -24
View File
@@ -2,30 +2,30 @@
/**
* Home Module · Recent
*
* config: { post_type, count, layout, title? }
*
* post_type 取值:
* 'post' → 最新文章
* 'aksrt_resource' → 最新资源(v3.4 起兼容 post + _aksrt_is_resource)
* config: { post_type: 'post'|'resource', count, layout, title? }
*/
defined('ABSPATH') || exit;
$cfg = get_query_var('aksrt_module_config', []);
if (!is_array($cfg)) $cfg = [];
if (!is_array($cfg)) {
$cfg = [];
}
$post_type = (string) ($cfg['post_type'] ?? 'post');
$count = max(1, min(20, (int) ($cfg['count'] ?? 6)));
$layout = (string) ($cfg['layout'] ?? 'card');
$title = (string) ($cfg['title'] ?? '');
$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)));
$layout = (string) ($cfg['layout'] ?? 'card');
$title = (string) ($cfg['title'] ?? '');
if (!in_array($layout, ['card', 'list', 'masonry', 'grid-cms'], true)) {
$layout = 'card';
}
if (!in_array($post_type, ['post', 'aksrt_resource'], true)) $post_type = 'post';
$is_resource_module = $post_type === 'aksrt_resource';
$is_resource_module = $scope === 'resource';
$args = [
'post_type' => 'post',
'posts_per_page' => $count,
'post_status' => 'publish',
'no_found_rows' => true,
@@ -33,16 +33,11 @@ $args = [
'order' => 'DESC',
];
if ($is_resource_module) {
$args['post_type'] = function_exists('aksrt_resource_post_types') ? aksrt_resource_post_types() : ['post'];
if (!post_type_exists('aksrt_resource')) {
$args['meta_query'] = [[
'key' => '_aksrt_is_resource',
'value' => '1',
'compare' => '=',
]];
}
} else {
$args['post_type'] = 'post';
$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);
@@ -53,7 +48,7 @@ if (!$query->have_posts()) {
$default_title = $is_resource_module ? __('最新资源', 'aksrt') : __('最新文章', 'aksrt');
$display_title = $title ?: $default_title;
$archive_link = $is_resource_module
$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'));
?>
@@ -78,7 +73,8 @@ $archive_link = $is_resource_module
}
set_query_var('aksrt_post_card_layout', '');
set_query_var('aksrt_post_card_scene', '');
wp_reset_postdata();
?>
</div>
</section>
<?php
wp_reset_postdata();