WordPress教程

WordPress 主题模板如果调用最新的评论

阿里云

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

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

也想出现在这里?联系我们
创客主机
  1. <?php
  2. $comments = get_comments('status=approve&number=6&order=modified');
  3. $output = '';
  4. foreach ($comments as $comment) {
  5.   $com_excerpt = $comment->comment_content;
  6.   $excerpt_len = mb_strlen($comment->comment_content, 'utf-8');
  7.   if ($excerpt_len > 46) $com_excerpt = mb_substr($com_excerpt, 0, 46, 'utf-8').'...';
  8.   $output .= $comment->comment_author_email.$comment->comment_author.$comment->comment_date_gmt.$com_excerpt.$comment->post_title.get_comment_link( $comment->comment_ID );
  9. }
  10.   $output = convert_smilies($output);
  11.   echo $output;
  12. ?>

WordPress 主题模板如果调用最新的评论

已有 86 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!