refactor(resource): drop aksrt_resource CPT residue, post+meta only
This commit is contained in:
1 parent
24c135aeec
commit
1af0e9b753
22 files changed
+362
-986
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* Home Module · Hotspot 热点推荐
|
||||
*
|
||||
* 纯文章列表(无图片),仅桌面端显示。
|
||||
* config: { count, post_type, source, title? }
|
||||
* config: { count, post_type: 'post'|'resource', source, title? }
|
||||
*
|
||||
* source:
|
||||
* 'auto' → 优先读取 aksrt_recommend meta,不足时用最新补充
|
||||
@@ -13,36 +13,39 @@
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$cfg = get_query_var('aksrt_module_config', []);
|
||||
if (!is_array($cfg)) $cfg = [];
|
||||
if (!is_array($cfg)) {
|
||||
$cfg = [];
|
||||
}
|
||||
|
||||
$count = max(3, min(20, (int) ($cfg['count'] ?? 6)));
|
||||
$post_type = (string) ($cfg['post_type'] ?? 'post');
|
||||
$source = (string) ($cfg['source'] ?? 'auto');
|
||||
$title = (string) ($cfg['title'] ?? '');
|
||||
$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');
|
||||
$title = (string) ($cfg['title'] ?? '');
|
||||
|
||||
if (!in_array($source, ['auto', 'recent', 'views'], true)) {
|
||||
$source = 'auto';
|
||||
}
|
||||
if (!in_array($post_type, ['post', 'aksrt_resource'], true)) {
|
||||
$post_type = 'post';
|
||||
}
|
||||
|
||||
$is_resource = $post_type === 'aksrt_resource';
|
||||
$ptypes = $is_resource && function_exists('aksrt_resource_post_types')
|
||||
? aksrt_resource_post_types()
|
||||
: [$post_type];
|
||||
$is_resource = $scope === 'resource';
|
||||
|
||||
// 构建查询参数
|
||||
$args = [
|
||||
'post_type' => $ptypes,
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => $count,
|
||||
'post_status' => 'publish',
|
||||
'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') {
|
||||
// 优先推荐文章,不足时用最新补充
|
||||
$args['meta_query'] = [
|
||||
$meta_query[] = [
|
||||
'relation' => 'OR',
|
||||
['key' => 'aksrt_recommend', 'value' => '1', 'compare' => '='],
|
||||
['key' => 'aksrt_recommend', 'compare' => 'NOT EXISTS'],
|
||||
@@ -58,6 +61,12 @@ if ($source === 'auto') {
|
||||
$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);
|
||||
if (!$query->have_posts()) {
|
||||
wp_reset_postdata();
|
||||
@@ -81,10 +90,10 @@ $display_title = $title ?: $default_title;
|
||||
$rank = 1;
|
||||
while ($query->have_posts()) :
|
||||
$query->the_post();
|
||||
$cats = get_the_category();
|
||||
$cats = get_the_category();
|
||||
$cat_name = $cats ? $cats[0]->name : '';
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_res_view_count', true);
|
||||
?>
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_res_view_count', true);
|
||||
?>
|
||||
<li class="hotspot__item">
|
||||
<span class="hotspot__num hotspot__num--<?php echo $rank <= 3 ? 'top' : 'normal'; ?>"><?php echo (int) $rank; ?></span>
|
||||
<div class="hotspot__body">
|
||||
@@ -102,7 +111,7 @@ $display_title = $title ?: $default_title;
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
<?php
|
||||
$rank++;
|
||||
endwhile;
|
||||
wp_reset_postdata();
|
||||
|
||||
Reference in new issue
Block a user