fix(phase1): backfill pagination, fix card stacking, unify archive render

- Backfill aksrt_render_pagination() into inc/helpers/aksrt-template-tags.php
  (numbered + load_more/infinite branches, \AKSRT\Settings\Settings facade)
- post-card.css: drop display:block !important from base .posts-item so
  .posts-item.card inline-block 3-col grid wins; scope <posts> block forcing
- archive-resources.php: replace hand-written .posts-row.ajaxpager +
  get_template_part loop with aksrt_render_post_list() + aksrt_render_pagination()

Refs .specs/plans/zibll-widgets-1to1.md Phase 1 (US2/US3/US5)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-07-30 19:05:43 +08:00
parent 5061977b72
commit 98aeee3cc1
3 changed files with 139 additions and 13 deletions
+17 -11
View File
@@ -159,18 +159,24 @@ $has_filter = $current_orderby !== 'date' || $current_price !== 'all' || $price_
</nav> </nav>
<?php if (have_posts()) : ?> <?php if (have_posts()) : ?>
<div class="posts-row ajaxpager tab-pane"> <?php
<?php $render_config = function_exists('aksrt_resolve_post_list_render_config')
set_query_var('aksrt_post_card_layout', 'card'); ? aksrt_resolve_post_list_render_config([
while (have_posts()) : 'context' => 'archive',
the_post(); 'overrides' => ['mode' => 'card'],
get_template_part('templates/parts/content', 'post-card'); ])
endwhile; : ['context' => 'archive', 'mode' => 'card'];
set_query_var('aksrt_post_card_layout', '');
?>
</div>
<?php aksrt_render_pagination(); ?> if (function_exists('aksrt_render_post_list')) {
aksrt_render_post_list(null, array_merge($render_config, ['wrapper_class' => 'content-stream__list']));
}
if (function_exists('aksrt_render_pagination')) {
aksrt_render_pagination(null, [
'query_context' => 'archive',
'render_config' => $render_config,
]);
}
?>
<?php else : ?> <?php else : ?>
<div class="no-results"> <div class="no-results">
<p><?php esc_html_e('暂无资源。', 'aksrt'); ?></p> <p><?php esc_html_e('暂无资源。', 'aksrt'); ?></p>
+6 -2
View File
@@ -28,8 +28,6 @@
posts.posts-item, posts.posts-item,
article.posts-item, article.posts-item,
.posts-item { .posts-item {
/* Custom element <posts> is inline by default — force block layout. */
display: block !important;
opacity: 1 !important; opacity: 1 !important;
visibility: visible !important; visibility: visible !important;
padding: 20px; padding: 20px;
@@ -45,6 +43,12 @@ article.posts-item,
opacity: 1; opacity: 1;
} }
/* Custom element <posts> is inline by default — force block layout here only,
scoped so it never overrides .posts-item.card inline-block grid (Phase 1 fix). */
posts.posts-item {
display: block;
}
.posts-item.list { .posts-item.list {
display: block; display: block;
width: 100%; width: 100%;
+116
View File
@@ -1126,6 +1126,122 @@ if (!function_exists('aksrt_render_comment_pagination')) {
} }
} }
// ============================================================
// 模板标签:文章列表分页渲染
// ============================================================
if (!function_exists('aksrt_render_pagination')) {
/**
* 渲染文章列表分页(根据后台配置选择模式)。
*
* Zibll 对齐:numbered = 数字分页按钮;load_more/infinite = AJAX 追加。
*
* @param WP_Query|null $query 可选,传入自定义查询对象;默认用主查询。
* @param array<string,mixed> $args {
* @type string $query_context search|archive|home|tag|category... 供 AJAX 路由解析。
* @type array<string,mixed> $render_config 透传给 AJAX 渲染器(aksrt_resolve_post_list_render_config)。
* }
*/
function aksrt_render_pagination(?WP_Query $query = null, array $args = []): void {
$pagination_mode = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_post_pagination_mode()
: 'numbered';
if ($pagination_mode === 'numbered') {
global $wp_query;
$q = $query ?? $wp_query;
if (!($q instanceof WP_Query) || $q->max_num_pages <= 1) {
return;
}
$current_page = max(1, (int) $q->get('paged'), (int) get_query_var('paged'), (int) get_query_var('page'));
$max_pages = (int) $q->max_num_pages;
$links = paginate_links([
'total' => $max_pages,
'current' => $current_page,
'mid_size' => 2,
'prev_text' => '<span aria-hidden="true">‹</span>',
'next_text' => '<span aria-hidden="true">›</span>',
'type' => 'plain',
]);
if (empty($links)) {
return;
}
echo '<div class="pagenav ajax-pag aksrt-pagination content-stream__footer-nav">';
echo wp_kses_post($links);
if ($max_pages > 8) {
echo '<span class="pag-jump">';
echo '<input type="number" class="jump-input" min="1" max="' . esc_attr((string) $max_pages) . '" value="' . esc_attr((string) $current_page) . '" data-max-pages="' . esc_attr((string) $max_pages) . '" />';
echo '<button type="button" class="ajax-next order-ajax-next" data-jump-archive="1">' . esc_html__('跳转', 'aksrt') . '</button>';
echo '</span>';
}
echo '</div>';
return;
}
// load_more / infinite 模式
global $wp_query;
$q = $query ?? $wp_query;
if (!($q instanceof WP_Query)) {
return;
}
$max_pages = (int) $q->max_num_pages;
$current_page = max(1, (int) $q->get('paged'), (int) get_query_var('paged'), (int) get_query_var('page'));
if ($current_page >= $max_pages) {
return;
}
$query_context = '';
if (!empty($args['query_context']) && is_string($args['query_context'])) {
$query_context = sanitize_key($args['query_context']);
} elseif (is_search()) {
$query_context = 'search';
} elseif (is_archive()) {
$query_context = 'archive';
}
$query_vars = $q->query_vars;
if (!is_array($query_vars)) {
$query_vars = [];
} else {
unset($query_vars['paged'], $query_vars['page']);
}
$render_config = !empty($args['render_config']) && is_array($args['render_config'])
? $args['render_config']
: [];
$trigger_text = __('加载更多', 'aksrt');
if (class_exists('\AKSRT\Settings\Settings')) {
$list_settings = \AKSRT\Settings\Settings::get_post_list_style_settings();
if (!empty($list_settings['ajax_trigger_text'])) {
$trigger_text = (string) $list_settings['ajax_trigger_text'];
}
}
?>
<div class="text-center theme-pagination ajax-pag ajax-pagination aksrt-pagination-ajax content-stream__footer-nav"
data-mode="<?php echo esc_attr($pagination_mode); ?>"
data-next-page="<?php echo esc_attr((string) ($current_page + 1)); ?>"
data-max-pages="<?php echo esc_attr((string) $max_pages); ?>"
data-query-context="<?php echo esc_attr($query_context); ?>"
data-query-vars="<?php echo esc_attr(wp_json_encode($query_vars)); ?>"
data-render-config="<?php echo esc_attr(wp_json_encode($render_config)); ?>"
data-lazyload-action="ias">
<div class="next-page ajax-next aksrt-load-more-btn" lazyload-action="ias" role="button" tabindex="0">
<?php echo esc_html($trigger_text); ?>
</div>
<div class="aksrt-loading-indicator" style="display:none;" aria-hidden="true">
<i class="fas fa-spinner fa-spin"></i>
<span><?php esc_html_e('加载中…', 'aksrt'); ?></span>
</div>
</div>
<?php
}
}
/** /**
* Auto-fill missing alt attributes on images in post content. * Auto-fill missing alt attributes on images in post content.
* *