Files
wordpress-theme-aksrt/templates/parts/user-home/uh-comments.php
T

77 lines
2.7 KiB
PHP

<?php
/**
* 公开用户主页 — 评论列表
*
* @package AKSRT
* @since 5.0.0
*/
defined('ABSPATH') || exit;
$user_id = $args['user_id'] ?? 0;
$per_page = $args['per_page'] ?? 15;
$paged = max(1, get_query_var('paged'));
$total = get_comments([
'user_id' => $user_id,
'status' => 'approve',
'post_status' => 'publish',
'count' => true,
]);
$comments = get_comments([
'user_id' => $user_id,
'status' => 'approve',
'post_status' => 'publish',
'number' => $per_page,
'offset' => ($paged - 1) * $per_page,
'orderby' => 'comment_date_gmt',
'order' => 'DESC',
]);
$max_pages = ceil($total / $per_page);
?>
<div class="uh-comments">
<?php if (!empty($comments)) : ?>
<div class="uh-comments__list">
<?php foreach ($comments as $comment) :
$post = get_post($comment->comment_post_ID);
if (!$post) continue;
?>
<div class="uh-comments__item">
<div class="uh-comments__header">
<a href="<?php echo esc_url(get_permalink($post->ID)); ?>" class="uh-comments__post-title">
<?php echo esc_html($post->post_title); ?>
</a>
<span class="uh-comments__date"><?php echo esc_html(get_comment_date('Y-m-d', $comment)); ?></span>
</div>
<div class="uh-comments__body">
<?php echo function_exists('aksrt_render_comment_content') ? aksrt_render_comment_content((string) get_comment_text($comment)) : wp_kses_post((string) $comment->comment_content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ($max_pages > 1) : ?>
<div class="aksrt-pagination">
<?php
echo paginate_links([
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
'format' => '?tab=comments&paged=%#%',
'current' => $paged,
'total' => $max_pages,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="empty-state empty-state--sm">
<div class="empty-state__icon"><i class="far fa-comment-dots"></i></div>
<p class="empty-state__title"><?php esc_html_e('暂无评论', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>