wordpress调用最新的评论的教程

在制作wordpress主题时,要在首页显示最新的评论信息,发现用get_comments非常方便,比我以前用SQL查询要简单很多。

具体的代码如下,样式及html标签可根据自己的需要添加即可,灵活性非常好。

<?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;
?>

版权声明:本文由 鹿泽笔记 原创发布。

本文链接:https://www.bailuze.com/9539.html

许可协议:本文标题《wordpress调用最新的评论的教程》,转载请注明文章出处及原始链接。

鹿泽
鹿泽

深耕 SEO优化 十二年,从个人博客爱好者到专业谷歌优化顾问的成长之路。技术派SEO、全域流量技术运营专家,拥有多年从业经验,热衷于分析算法逻辑与推理的精准匹配。