Files
wordpress-theme-aksrt/templates/parts/user-center/uc-comments.php
T

82 lines
3.0 KiB
PHP

<?php
/**
* 用户中心 — 我的评论
*
* @package AKSRT
* @since 5.0.0
*/
defined('ABSPATH') || exit;
$user_id = get_current_user_id();
$per_page = 15;
$paged = max(1, get_query_var('paged'));
$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',
'count' => true,
]);
$total_comments = $comments;
$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_comments / $per_page);
?>
<div class="uc-comments" id="uc-comments">
<?php if (!empty($comments)) : ?>
<div class="uc-comments__list">
<?php foreach ($comments as $comment) :
$post = get_post($comment->comment_post_ID);
if (!$post) continue;
?>
<div class="uc-comments__item">
<div class="uc-comments__header">
<a href="<?php echo esc_url(get_permalink($post->ID)); ?>" class="uc-comments__post-title">
<?php echo esc_html($post->post_title); ?>
</a>
<span class="uc-comments__date"><?php echo esc_html(get_comment_date('Y-m-d', $comment)); ?></span>
</div>
<div class="uc-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' => '?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>
<p class="empty-state__desc"><?php esc_html_e('去文章下方发表你的看法吧~', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>