feat(widgets): category recommend/tabs residual + batch22-24 CSS
Use graphic_card heroes and mini post strips for category recommend, prefer shared mini list in category block sidebar fallback, admin empty for product tabs, and forum/user residual styles.
This commit is contained in:
1 parent
8b5ca8f287
commit
4368a3c586
5 files changed
+184
-67
No files matched your search
@@ -215,25 +215,26 @@ if (!function_exists('aksrt_home_widget_render_post_grid')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: simple sidebar list
|
||||
// Fallback: shared mini list (lazy thumbs + meta).
|
||||
if (function_exists('aksrt_render_mini_list')) {
|
||||
echo '<div class="widget-tab-posts__list widget-tab-posts__list--mini aksrt-home-widget__sidebar-list">';
|
||||
aksrt_render_mini_list($query, ['context' => 'sidebar', 'show_thumb' => true]);
|
||||
echo '</div>';
|
||||
return;
|
||||
}
|
||||
echo '<ul class="widget-tab-posts__list aksrt-home-widget__sidebar-list">';
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
?>
|
||||
<li class="widget-tab-posts__item">
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<a href="<?php the_permalink(); ?>" class="widget-tab-posts__thumb">
|
||||
<?php the_post_thumbnail('thumbnail', ['loading' => 'lazy', 'class' => 'fit-cover']); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<div class="widget-tab-posts__info">
|
||||
<a href="<?php the_permalink(); ?>" class="widget-tab-posts__title"><?php the_title(); ?></a>
|
||||
<span class="widget-tab-posts__meta">
|
||||
<?php echo esc_html(human_time_diff(get_the_time('U'), current_time('timestamp')) . __('前', 'aksrt')); ?>
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
$thumb = get_the_post_thumbnail_url(get_the_ID(), 'thumbnail');
|
||||
echo '<li class="widget-tab-posts__item">';
|
||||
if ($thumb) {
|
||||
echo '<a href="' . esc_url(get_permalink()) . '" class="widget-tab-posts__thumb"><img class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" /></a>';
|
||||
}
|
||||
echo '<div class="widget-tab-posts__info">';
|
||||
echo '<a href="' . esc_url(get_permalink()) . '" class="widget-tab-posts__title">' . esc_html(get_the_title()) . '</a>';
|
||||
echo '<span class="widget-tab-posts__meta">' . esc_html(human_time_diff(get_the_time('U'), current_time('timestamp')) . __('前', 'aksrt')) . '</span>';
|
||||
echo '</div></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
wp_reset_postdata();
|
||||
|
||||
@@ -48,56 +48,82 @@ class CategoryRecommendWidget extends \WP_Widget {
|
||||
ob_start();
|
||||
printf('<div class="aksrt-category-recommend__grid ajax-item" style="--aksrt-recommend-columns:%d;">', (int) $columns);
|
||||
foreach ($cards as $card) {
|
||||
?>
|
||||
<article class="aksrt-category-recommend__card">
|
||||
<div class="aksrt-category-recommend__hero">
|
||||
<a href="<?php echo esc_url($card['link']); ?>">
|
||||
<?php if ($lazy['enabled']) : ?>
|
||||
<span class="aksrt-skeleton"></span>
|
||||
<img class="aksrt-category-recommend__cover aksrt-lazy" data-src="<?php echo esc_url($card['cover']); ?>" src="<?php echo esc_url($lazy['placeholder_url']); ?>" alt="<?php echo esc_attr($card['name']); ?>">
|
||||
<?php else : ?>
|
||||
<img class="aksrt-category-recommend__cover" src="<?php echo esc_url($card['cover']); ?>" alt="<?php echo esc_attr($card['name']); ?>">
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<span class="aksrt-category-recommend__badge"><?php echo esc_html(sprintf(_n('%d 篇文章', '%d 篇文章', $card['count'], 'aksrt'), $card['count'])); ?></span>
|
||||
<?php if ($show_views && $card['views'] > 0) : ?>
|
||||
<span class="aksrt-category-recommend__views">
|
||||
<i class="fas fa-eye" aria-hidden="true"></i>
|
||||
<?php echo esc_html(function_exists('aksrt_format_number') ? aksrt_format_number($card['views']) : number_format_i18n($card['views'])); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="aksrt-category-recommend__body">
|
||||
<div class="aksrt-category-recommend__meta">
|
||||
<h4 class="aksrt-category-recommend__name">
|
||||
<a href="<?php echo esc_url($card['link']); ?>"><?php echo esc_html($card['name']); ?></a>
|
||||
</h4>
|
||||
<?php if ($show_description && $card['description'] !== '') : ?>
|
||||
<p class="aksrt-category-recommend__desc"><?php echo esc_html($card['description']); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<ul class="aksrt-category-recommend__posts">
|
||||
<?php foreach ($card['posts'] as $post_item) : ?>
|
||||
<li class="aksrt-category-recommend__post">
|
||||
<a class="aksrt-category-recommend__post-link" href="<?php echo esc_url($post_item['link']); ?>">
|
||||
<?php echo esc_html($post_item['title']); ?>
|
||||
</a>
|
||||
<?php if ($show_dates && $post_item['date'] !== '') : ?>
|
||||
<span class="aksrt-category-recommend__date"><?php echo esc_html($post_item['date']); ?></span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if ($show_more) : ?>
|
||||
<div class="aksrt-home-widget__footer">
|
||||
<a class="aksrt-home-widget__more" href="<?php echo esc_url($card['link']); ?>">
|
||||
<?php esc_html_e('查看更多', 'aksrt'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</article>
|
||||
<?php
|
||||
$cover = (string) ($card['cover'] ?? '');
|
||||
$link = (string) ($card['link'] ?? '');
|
||||
$name = (string) ($card['name'] ?? '');
|
||||
$badge = sprintf(_n('%d 篇文章', '%d 篇文章', (int) $card['count'], 'aksrt'), (int) $card['count']);
|
||||
$more = '';
|
||||
if ($show_views && (int) $card['views'] > 0) {
|
||||
$v = function_exists('aksrt_format_number') ? aksrt_format_number((int) $card['views']) : number_format_i18n((int) $card['views']);
|
||||
$more = '<span class="aksrt-category-recommend__views"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html((string) $v) . '</span>';
|
||||
}
|
||||
echo '<article class="aksrt-category-recommend__card" data-aksrt-animate="fade-up">';
|
||||
if (function_exists('aksrt_graphic_card') && $cover !== '') {
|
||||
echo aksrt_graphic_card([ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
'type' => 'style-2',
|
||||
'class' => 'aksrt-category-recommend__hero mb10',
|
||||
'img' => $cover,
|
||||
'alt' => $name,
|
||||
'link' => ['url' => $link],
|
||||
'text1' => $name,
|
||||
'text2' => $show_description ? (string) $card['description'] : '',
|
||||
'text3' => $badge,
|
||||
'more' => $more,
|
||||
'lazy' => true,
|
||||
]);
|
||||
} else {
|
||||
echo '<div class="aksrt-category-recommend__hero">';
|
||||
echo '<a href="' . esc_url($link) . '">';
|
||||
if ($lazy['enabled']) {
|
||||
echo '<span class="aksrt-skeleton"></span>';
|
||||
echo '<img class="aksrt-category-recommend__cover aksrt-lazy" data-src="' . esc_url($cover) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="' . esc_attr($name) . '">';
|
||||
} else {
|
||||
echo '<img class="aksrt-category-recommend__cover" src="' . esc_url($cover) . '" alt="' . esc_attr($name) . '">';
|
||||
}
|
||||
echo '</a>';
|
||||
echo '<span class="aksrt-category-recommend__badge">' . esc_html($badge) . '</span>';
|
||||
echo $more; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-category-recommend__meta">';
|
||||
echo '<h4 class="aksrt-category-recommend__name"><a href="' . esc_url($link) . '">' . esc_html($name) . '</a></h4>';
|
||||
if ($show_description && $card['description'] !== '') {
|
||||
echo '<p class="aksrt-category-recommend__desc">' . esc_html((string) $card['description']) . '</p>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '<div class="aksrt-category-recommend__body">';
|
||||
// Prefer shared mini list when post IDs available.
|
||||
if (!empty($card['post_ids']) && function_exists('aksrt_render_mini_list')) {
|
||||
$q = new \WP_Query([
|
||||
'post_type' => 'any',
|
||||
'post__in' => array_map('intval', (array) $card['post_ids']),
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => count((array) $card['post_ids']),
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
]);
|
||||
echo '<div class="aksrt-category-recommend__posts posts-mini-wrap">';
|
||||
aksrt_render_mini_list($q, ['context' => 'widget', 'show_thumb' => true, 'show_meta' => $show_dates]);
|
||||
echo '</div>';
|
||||
wp_reset_postdata();
|
||||
} else {
|
||||
echo '<ul class="aksrt-category-recommend__posts">';
|
||||
foreach ($card['posts'] as $post_item) {
|
||||
echo '<li class="aksrt-category-recommend__post">';
|
||||
echo '<a class="aksrt-category-recommend__post-link" href="' . esc_url($post_item['link']) . '">' . esc_html($post_item['title']) . '</a>';
|
||||
if ($show_dates && $post_item['date'] !== '') {
|
||||
echo '<span class="aksrt-category-recommend__date">' . esc_html($post_item['date']) . '</span>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
if ($show_more) {
|
||||
echo '<div class="aksrt-home-widget__footer">';
|
||||
echo '<a class="aksrt-home-widget__more" href="' . esc_url($link) . '">' . esc_html__('查看更多', 'aksrt') . '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div></article>';
|
||||
}
|
||||
echo '</div>';
|
||||
return (string) ob_get_clean();
|
||||
|
||||
@@ -130,7 +130,7 @@ class CategoryTabsWidget extends \WP_Widget {
|
||||
if(showMore&&more){
|
||||
html+='<div class="aksrt-home-widget__footer"><a class="aksrt-home-widget__more" href="'+more+'">查看更多</a></div>';
|
||||
}
|
||||
panel.innerHTML=html||'<p class="widget-empty">暂无文章</p>';
|
||||
panel.innerHTML=html||'<div class="ajax-item widget-empty muted-2-color">暂无文章</div>';
|
||||
panel.setAttribute('data-loaded','1');
|
||||
panel.classList.remove('is-ajax-loading');
|
||||
}).catch(function(){panel.classList.remove('is-ajax-loading');});
|
||||
|
||||
@@ -49,6 +49,13 @@ class WidgetProductTab extends \WP_Widget {
|
||||
$paginate = sanitize_key((string) ($instance['paginate'] ?? 'ajax'));
|
||||
$tabs = self::parse_tabs($tabs_raw);
|
||||
if (!$tabs) {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo function_exists('aksrt_get_widget_null')
|
||||
? aksrt_get_widget_null(__('请至少配置一个 TAB', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
: '<p class="widget-empty">' . esc_html__('请至少配置一个 TAB', 'aksrt') . '</p>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user