feat(frontend): replace article system with Zibll 9.0
This commit is contained in:
1 parent
2881c69e9c
commit
0f2ac6c34a
69 files changed
+2603
-4163
No files matched your search
@@ -568,12 +568,8 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
*/
|
||||
function aksrt_single_related_query_args(int $post_id, array $settings): array {
|
||||
$count = max(1, min(12, (int) ($settings['related_count'] ?? 6)));
|
||||
$type = sanitize_key((string) ($settings['related_source'] ?? ($settings['related_type'] ?? 'category')));
|
||||
if (!in_array($type, ['category', 'tag', 'random'], true)) {
|
||||
$type = 'category';
|
||||
}
|
||||
$orderby = sanitize_key((string) ($settings['related_orderby'] ?? 'views'));
|
||||
if (!in_array($orderby, ['rand', 'relevance', 'date', 'views', 'modified'], true)) {
|
||||
if (!in_array($orderby, ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'], true)) {
|
||||
$orderby = 'views';
|
||||
}
|
||||
|
||||
@@ -587,39 +583,22 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
'order' => 'DESC',
|
||||
];
|
||||
|
||||
if ($type === 'random') {
|
||||
$args['orderby'] = 'rand';
|
||||
return $args;
|
||||
}
|
||||
|
||||
$tax_query = ['relation' => 'OR'];
|
||||
if ($type === 'tag') {
|
||||
$tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']);
|
||||
if (!empty($tag_ids) && !is_wp_error($tag_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $tag_ids),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// category (default): OR across category + tags.
|
||||
$cat_ids = wp_get_post_terms($post_id, 'category', ['fields' => 'ids']);
|
||||
if (!empty($cat_ids) && !is_wp_error($cat_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $cat_ids),
|
||||
];
|
||||
}
|
||||
$tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']);
|
||||
if (!empty($tag_ids) && !is_wp_error($tag_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $tag_ids),
|
||||
];
|
||||
}
|
||||
$cat_ids = wp_get_post_terms($post_id, 'category', ['fields' => 'ids']);
|
||||
if (!empty($cat_ids) && !is_wp_error($cat_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $cat_ids),
|
||||
];
|
||||
}
|
||||
$tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']);
|
||||
if (!empty($tag_ids) && !is_wp_error($tag_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $tag_ids),
|
||||
];
|
||||
}
|
||||
|
||||
if (count($tax_query) > 1) {
|
||||
@@ -636,6 +615,17 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
case 'modified':
|
||||
$args['orderby'] = 'modified';
|
||||
break;
|
||||
case 'like':
|
||||
$args['meta_key'] = '_aksrt_like_count';
|
||||
$args['orderby'] = ['meta_value_num' => 'DESC', 'date' => 'DESC'];
|
||||
break;
|
||||
case 'favorite':
|
||||
$args['meta_key'] = '_aksrt_favorite_count';
|
||||
$args['orderby'] = ['meta_value_num' => 'DESC', 'date' => 'DESC'];
|
||||
break;
|
||||
case 'comment_count':
|
||||
$args['orderby'] = 'comment_count';
|
||||
break;
|
||||
case 'views':
|
||||
$args['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
@@ -651,10 +641,8 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
];
|
||||
$args['orderby'] = ['views_value' => 'DESC', 'date' => 'DESC'];
|
||||
break;
|
||||
case 'relevance':
|
||||
default:
|
||||
// Prefer date when no search relevance context.
|
||||
$args['orderby'] = 'date';
|
||||
$args['orderby'] = 'modified';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -695,74 +683,54 @@ if (!function_exists('aksrt_single_render_related')) :
|
||||
];
|
||||
|
||||
$query = new WP_Query($args);
|
||||
if (!$query->have_posts()) {
|
||||
wp_reset_postdata();
|
||||
$empty_wrap = 'theme-box relates' . ($style === 'img' ? ' relates-thumb' : '');
|
||||
?>
|
||||
<div class="<?php echo esc_attr($empty_wrap); ?>">
|
||||
<div class="box-body notop">
|
||||
<div class="title-theme"><?php echo esc_html($title); ?></div>
|
||||
</div>
|
||||
<div class="zib-widget">
|
||||
<?php echo function_exists('aksrt_get_null') ? aksrt_get_null(__('暂无相关文章', 'aksrt'), 40, 'null.svg', 'related-null', 220) : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
$wrap_class = 'theme-box relates' . ($style === 'img' ? ' relates-thumb' : '');
|
||||
$posts_html = '';
|
||||
$mini_cfg = aksrt_renderer_config([
|
||||
'type' => 'list',
|
||||
'show_number' => false,
|
||||
]);
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
$post = get_post();
|
||||
if (!($post instanceof WP_Post)) {
|
||||
continue;
|
||||
}
|
||||
if ($style === 'list') {
|
||||
$data = aksrt_renderer_collect_post_data($mini_cfg);
|
||||
if ($data) {
|
||||
$posts_html .= aksrt_renderer_mini($data, $mini_cfg);
|
||||
}
|
||||
} elseif ($style === 'img' && function_exists('aksrt_render_related_graphic_card')) {
|
||||
$posts_html .= aksrt_render_related_graphic_card($post);
|
||||
} else {
|
||||
$subtitle = class_exists('\AKSRT\Core\PostMetaBox')
|
||||
? (string) \AKSRT\Core\PostMetaBox::get_meta_value($post->ID, 'subtitle', '')
|
||||
: '';
|
||||
$posts_html .= '<li><a class="icon-circle" href="' . esc_url(get_permalink($post)) . '">' . esc_html(get_the_title($post) . $subtitle) . '</a></li>';
|
||||
}
|
||||
}
|
||||
wp_reset_postdata();
|
||||
if ($posts_html === '') {
|
||||
$posts_html = '<li>' . esc_html__('暂无相关文章', 'aksrt') . '</li>';
|
||||
}
|
||||
?>
|
||||
<div class="<?php echo esc_attr($wrap_class); ?>">
|
||||
<div class="box-body notop">
|
||||
<div class="title-theme"><?php echo esc_html($title); ?></div>
|
||||
</div>
|
||||
<div class="zib-widget">
|
||||
<?php if ($style === 'list' && function_exists('aksrt_render_post_list')) : ?>
|
||||
<?php
|
||||
// New route: single query only.
|
||||
aksrt_render_post_list($query, [
|
||||
'context' => 'related',
|
||||
'mode' => 'mini',
|
||||
'show_thumb' => true,
|
||||
'show_meta' => true,
|
||||
'show_number' => false,
|
||||
]);
|
||||
?>
|
||||
<?php if ($style === 'img') : ?>
|
||||
<div class="swiper-container swiper-scroll">
|
||||
<div class="swiper-wrapper"><?php echo $posts_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="swiper-button-prev"></div>
|
||||
<div class="swiper-button-next"></div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<?php
|
||||
$posts_html = '';
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
$p = get_post();
|
||||
if (!($p instanceof WP_Post)) {
|
||||
continue;
|
||||
}
|
||||
if ($style === 'img' && function_exists('aksrt_render_related_graphic_card')) {
|
||||
$posts_html .= aksrt_render_related_graphic_card($p);
|
||||
} else {
|
||||
$posts_html .= '<li><a class="icon-circle" href="' . esc_url(get_permalink($p)) . '">' . esc_html(get_the_title($p)) . '</a></li>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($style === 'img') : ?>
|
||||
<div class="swiper-container swiper-scroll">
|
||||
<div class="swiper-wrapper">
|
||||
<?php echo $posts_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<div class="swiper-button-prev"></div>
|
||||
<div class="swiper-button-next"></div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<ul class="no-thumb">
|
||||
<?php echo $posts_html !== '' ? $posts_html : '<li>' . esc_html__('暂无相关文章', 'aksrt') . '</li>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<ul class="no-thumb"><?php echo $posts_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
wp_reset_postdata();
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
Reference in new issue
Block a user