feat(widgets): shared forum topic/plate renderers for list depth
Extract aksrt_render_forum_topic_mini/detail and plate row/card helpers, then wire TopicLists, PlateLists, and BoardList for zibll-aligned DOM, lazy thumbs, and identity-aware topic rows.
This commit is contained in:
1 parent
8b73a9443f
commit
9c5ac01119
5 files changed
+443
-42
No files matched your search
@@ -57,27 +57,44 @@ class WidgetForumBoardList extends \WP_Widget {
|
||||
$plates = get_posts($query_args);
|
||||
if ($plates) {
|
||||
ob_start();
|
||||
echo '<ul class="aksrt-forum-widget__boards style-' . esc_attr($style) . ' ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
$icon = (string) get_post_meta($plate->ID, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($plate->ID, '_aksrt_posts_count', true);
|
||||
$thumb = get_the_post_thumbnail_url($plate->ID, 'thumbnail');
|
||||
echo '<li class="aksrt-forum-widget__board">';
|
||||
echo '<a href="' . esc_url(get_permalink($plate)) . '">';
|
||||
if ($style === 'mini' && $thumb) {
|
||||
echo '<img class="aksrt-forum-widget__thumb" src="' . esc_url($thumb) . '" alt="" width="28" height="28" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '"></i> ';
|
||||
if ($style === 'mini' && function_exists('aksrt_render_plate_row')) {
|
||||
// Compact mini still uses shared plate row for consistent DOM/lazy.
|
||||
echo '<div class="plate-lists aksrt-forum-widget__boards style-mini ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
echo aksrt_render_plate_row($plate); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '<span class="aksrt-forum-widget__name">' . esc_html(get_the_title($plate)) . '</span>';
|
||||
echo '<span class="aksrt-forum-widget__count">' . esc_html((string) $count) . '</span>';
|
||||
echo '</a></li>';
|
||||
echo '</div>';
|
||||
} elseif (function_exists('aksrt_render_plate_row')) {
|
||||
echo '<div class="plate-lists aksrt-forum-widget__boards style-list ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
echo aksrt_render_plate_row($plate); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<ul class="aksrt-forum-widget__boards style-' . esc_attr($style) . ' ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
$icon = (string) get_post_meta($plate->ID, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($plate->ID, '_aksrt_posts_count', true);
|
||||
$thumb = get_the_post_thumbnail_url($plate->ID, 'thumbnail');
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
echo '<li class="aksrt-forum-widget__board">';
|
||||
echo '<a href="' . esc_url(get_permalink($plate)) . '">';
|
||||
if ($style === 'mini' && $thumb) {
|
||||
echo '<img class="aksrt-forum-widget__thumb aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" width="28" height="28" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '"></i> ';
|
||||
}
|
||||
echo '<span class="aksrt-forum-widget__name">' . esc_html(get_the_title($plate)) . '</span>';
|
||||
echo '<span class="aksrt-forum-widget__count">' . esc_html((string) $count) . '</span>';
|
||||
echo '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
echo '</ul>';
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Taxonomy fallback.
|
||||
$term_args = [
|
||||
'taxonomy' => 'aksrt_forum_board',
|
||||
|
||||
@@ -88,20 +88,27 @@ class WidgetForumPlateLists extends \WP_Widget {
|
||||
return '';
|
||||
}
|
||||
ob_start();
|
||||
$self = new self();
|
||||
if ($style === 'card') {
|
||||
echo '<div class="aksrt-plate-cards ajax-item">';
|
||||
echo '<div class="panel-plate scroll-plate aksrt-plate-cards">';
|
||||
foreach ($plates as $post) {
|
||||
if ($post instanceof \WP_Post) {
|
||||
$self->render_card($post);
|
||||
if (function_exists('aksrt_render_plate_card')) {
|
||||
echo aksrt_render_plate_card($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
(new self())->render_card($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<div class="aksrt-plate-lists ajax-item">';
|
||||
echo '<div class="plate-lists aksrt-plate-lists">';
|
||||
foreach ($plates as $post) {
|
||||
if ($post instanceof \WP_Post) {
|
||||
$self->render_row($post);
|
||||
if (function_exists('aksrt_render_plate_row')) {
|
||||
echo aksrt_render_plate_row($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
(new self())->render_row($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
@@ -154,42 +161,56 @@ class WidgetForumPlateLists extends \WP_Widget {
|
||||
}
|
||||
|
||||
public function render_row(\WP_Post $post): void {
|
||||
if (function_exists('aksrt_render_plate_row')) {
|
||||
echo aksrt_render_plate_row($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$thumb = get_the_post_thumbnail_url($id, 'thumbnail');
|
||||
$icon = (string) get_post_meta($id, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$desc = $post->post_excerpt !== '' ? $post->post_excerpt : wp_trim_words(wp_strip_all_tags($post->post_content), 18);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
echo '<a class="aksrt-plate-item" href="' . esc_url($url) . '">';
|
||||
echo '<div class="aksrt-plate-item__thumb">';
|
||||
echo '<a class="plate-item flex aksrt-plate-item" href="' . esc_url($url) . '">';
|
||||
echo '<div class="plate-thumb aksrt-plate-item__thumb">';
|
||||
if ($thumb) {
|
||||
echo '<img src="' . esc_url($thumb) . '" alt="" loading="lazy" />';
|
||||
echo '<img class="aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>';
|
||||
} else {
|
||||
echo '<i class="fas fa-comments" aria-hidden="true"></i>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-plate-item__body">';
|
||||
echo '<div class="aksrt-plate-item__title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<div class="item-info flex1 aksrt-plate-item__body">';
|
||||
echo '<div class="info-header"><div class="forum-title aksrt-plate-item__title">' . esc_html(get_the_title($post)) . '</div></div>';
|
||||
if ($desc !== '') {
|
||||
echo '<div class="aksrt-plate-item__desc">' . esc_html($desc) . '</div>';
|
||||
echo '<div class="aksrt-plate-item__desc muted-2-color em09">' . esc_html($desc) . '</div>';
|
||||
}
|
||||
echo '<div class="aksrt-plate-item__meta"><span>' . esc_html(sprintf(/* translators: %d topic count */ __('%d 帖', 'aksrt'), $count)) . '</span></div>';
|
||||
echo '</div></a>';
|
||||
}
|
||||
|
||||
public function render_card(\WP_Post $post): void {
|
||||
if (function_exists('aksrt_render_plate_card')) {
|
||||
echo aksrt_render_plate_card($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$thumb = get_the_post_thumbnail_url($id, 'medium');
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$follow = (int) get_post_meta($id, '_aksrt_follow_count', true);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
echo '<a class="aksrt-plate-card" href="' . esc_url($url) . '">';
|
||||
echo '<div class="aksrt-plate-card__cover"' . ($thumb ? ' style="background-image:url(' . esc_url($thumb) . ')"' : '') . '></div>';
|
||||
echo '<div class="aksrt-plate-card__title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<a class="plate-card aksrt-plate-card" href="' . esc_url($url) . '">';
|
||||
echo '<div class="plate-thumb aksrt-plate-card__cover">';
|
||||
if ($thumb) {
|
||||
echo '<img class="aksrt-lazy lazyload fit-cover" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" />';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-plate-card__title forum-title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<div class="aksrt-plate-card__meta">';
|
||||
echo '<span>' . esc_html(sprintf(__('%d 帖', 'aksrt'), $count)) . '</span>';
|
||||
echo '<span>' . esc_html(sprintf(__('%d 关注', 'aksrt'), $follow)) . '</span>';
|
||||
|
||||
@@ -79,26 +79,25 @@ class WidgetForumTopicLists extends \WP_Widget {
|
||||
if (!$q->have_posts()) {
|
||||
return '';
|
||||
}
|
||||
$list_class = $style === 'detail' ? 'aksrt-ftopic-list is-detail' : 'aksrt-ftopic-list is-mini';
|
||||
ob_start();
|
||||
echo '<ul class="' . esc_attr($list_class) . '">';
|
||||
echo $style === 'detail'
|
||||
? '<div class="forum-posts-lists aksrt-ftopic-list is-detail">'
|
||||
: '<div class="forum-posts-lists aksrt-ftopic-list is-mini">';
|
||||
while ($q->have_posts()) {
|
||||
$q->the_post();
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_views', true);
|
||||
echo '<li class="aksrt-ftopic-list__item ajax-item">';
|
||||
echo '<a class="aksrt-ftopic-list__link" href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a>';
|
||||
if ($style === 'detail') {
|
||||
echo '<div class="aksrt-ftopic-list__meta">';
|
||||
echo '<span>' . esc_html(get_the_author()) . '</span>';
|
||||
echo '<span>' . esc_html(get_the_date()) . '</span>';
|
||||
echo '<span><i class="fas fa-eye"></i> ' . esc_html((string) $views) . '</span>';
|
||||
echo '</div>';
|
||||
if ($style === 'detail' && function_exists('aksrt_render_forum_topic_detail')) {
|
||||
echo aksrt_render_forum_topic_detail(null, 'ajax-item', true); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} elseif (function_exists('aksrt_render_forum_topic_mini')) {
|
||||
echo aksrt_render_forum_topic_mini(null, 'ajax-item', true); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_views', true);
|
||||
echo '<div class="aksrt-ftopic-list__item ajax-item">';
|
||||
echo '<a class="aksrt-ftopic-list__link" href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a>';
|
||||
echo '<span class="aksrt-ftopic-list__views">' . esc_html((string) $views) . '</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
wp_reset_postdata();
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user