WordPress 调用最新评论列表

Gavin Wu 2022年05月15日 8:05 Wordpress 915 Views

WordPress 调用最新评论列表的代码

1
2
3
4
5
6
7
8
9
10
11
12
<?php
$comments = get_comments('status=approve&number=6&order=modified');
$output = '';
foreach ($comments as $comment) {
  $com_excerpt = $comment->comment_content;
  $excerpt_len = mb_strlen($comment->comment_content, 'utf-8');
  if ($excerpt_len > 46) $com_excerpt = mb_substr($com_excerpt, 0, 46, 'utf-8').'...';
  $output .= $comment->comment_author_email.$comment->comment_author.$comment->comment_date_gmt.$com_excerpt.$comment->post_title.get_comment_link( $comment->comment_ID );
}
  $output = convert_smilies($output);
  echo $output;
?>

number=6表示调用的评论数量

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Top