fix(widgets): resolve term covers through the canonical category chain

The shared term cover helper read aksrt_cover_url/cover_url term meta,
keys this theme never writes, so 分类图文卡片 dropped every card and
分类聚合卡片 always rendered an empty cover box. Resolve covers the way
the rest of the theme does (aksrt_category_cover_id → latest thumbnailed
post in the term), and let the aggregation card fall back to the theme
placeholder while term cards stay hidden without a real cover.
This commit is contained in:
2026-09-05 12:05:12 +08:00
parent 6cbcca689d
commit f5a7c7a833
+27 -7
View File
@@ -40,16 +40,36 @@ endif;
if (!function_exists('aksrt_widget_term_cover_url')) :
/**
* Category cover image URL with the theme meta fallback chain.
* Category cover image URL, resolved through the theme's canonical chain:
* explicit term cover → latest thumbnailed post inside the term → optional
* default placeholder. The reference hides term cards without a real cover
* while the aggregation card always falls back to a default image, so the
* last step is opt-in via $default_fallback.
*/
function aksrt_widget_term_cover_url(int $term_id): string {
foreach (['aksrt_cover_url', 'cover_url'] as $meta_key) {
$url = esc_url_raw((string) get_term_meta($term_id, $meta_key, true));
function aksrt_widget_term_cover_url(int $term_id, bool $default_fallback = false): string {
$cover_id = (int) get_term_meta($term_id, 'aksrt_category_cover_id', true);
if ($cover_id > 0) {
$url = wp_get_attachment_url($cover_id);
if ($url !== '') {
return $url;
return (string) $url;
}
}
return '';
$posts = get_posts([
'category__in' => [$term_id],
'posts_per_page' => 1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => [['key' => '_thumbnail_id', 'compare' => 'EXISTS']],
'fields' => 'ids',
]);
if (!empty($posts)) {
$url = get_the_post_thumbnail_url((int) $posts[0], 'medium_large');
if ($url) {
return (string) $url;
}
}
return $default_fallback ? get_template_directory_uri() . '/assets/img/placeholder.svg' : '';
}
endif;
@@ -195,7 +215,7 @@ if (!function_exists('aksrt_widget_term_aggregation')) :
$href = esc_url((string) $href);
$icon = '<i class="fa fa-folder-open-o mr6" aria-hidden="true"></i>';
$img = aksrt_widget_term_cover_url((int) $term->term_id);
$img = aksrt_widget_term_cover_url((int) $term->term_id, true);
$img_html = aksrt_graphic_card([
'class' => '',
'img' => $img,