fix(user-home): align profile comments with reference theme

This commit is contained in:
kate522 committed 2026-10-04 19:11:27 +08:00
1 parent 00817766a6
commit 56bbb63afd
8 files changed
+261 -131

No files matched your search

+35 -14
View File
@@ -3,8 +3,8 @@
* Public user home — comments tab panel body.
*
* Rendered inside the #panel-comments wrapper on the public user home and via
* the aksrt/v1 user-home panel REST fragment. Pagination is button-driven
* (aksrt_render_user_home_pagination) and never touches the URL.
* the aksrt/v1 user-home panel REST fragment. Later pages append through the
* existing REST route and never touch the URL.
*
* @package AKSRT
*/
@@ -14,26 +14,47 @@ defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$user_comments = get_comments([
'user_id' => $user_id,
'status' => 'approve',
'number' => $per_page,
'offset' => ($comments_page - 1) * $per_page,
$is_own_profile = !empty($is_own_profile);
$comments_page = max(1, (int) $comments_page);
$per_page = max(1, (int) $per_page);
$comment_offset = ($comments_page - 1) * $per_page;
$comment_status = $is_own_profile ? 'all' : 'approve';
$comment_args = [
'user_id' => (int) $user_id,
'status' => $comment_status,
'type' => 'comment',
'post_type' => ['post'],
'orderby' => 'comment_date_gmt',
'order' => 'DESC',
'update_comment_meta_cache' => false,
]);
];
$user_comments = get_comments(array_merge($comment_args, [
'number' => $per_page,
'offset' => $comment_offset,
]));
$comments_total = (int) get_comments(array_merge($comment_args, ['count' => true]));
$has_more = $comments_total > ($comment_offset + count($user_comments));
if ($user_comments) :
?>
<div class="profile-comment-list">
<?php foreach ($user_comments as $c) : ?>
<?php
get_template_part('templates/parts/content', 'profile-comment-item', ['comment' => $c]);
get_template_part('templates/parts/content', 'profile-comment-item', [
'comment' => $c,
]);
?>
<?php endforeach; ?>
</div>
<?php
aksrt_render_user_home_pagination((int) ceil($comment_count / max(1, $per_page)), (int) $comments_page);
else :
aksrt_render_profile_empty($svg_empty_comment, __('TA 还没有发表评论', 'aksrt'));
endif;
<?php if ($has_more) : ?>
<div class="profile-comment-more text-center theme-pagination ajax-pag">
<div class="next-page ajax-next">
<button type="button" data-uh-comments-next="<?php echo esc_attr((string) ($comments_page + 1)); ?>">
<?php esc_html_e('加载更多', 'aksrt'); ?>
</button>
</div>
</div>
<?php endif; ?>
<?php else : ?>
<?php aksrt_render_profile_empty($svg_empty_comment, __('TA 还没有发表评论', 'aksrt')); ?>
<?php endif; ?>