不用小工具制作一个WordPress的最新评论列表

WordPress的小工具简单但是不够灵活,可以不用它,手动制作一个最新评论列表,这里需要用到的函数是 get_comments

WordPress的最新评论列表
WordPress的最新评论列表
/**
 * 最新评论
 * http://codex.wordpress.org.cn/Function_Reference/get_comments
 */
$comments = get_comments('status=approve&number=10&order=DESC');
if( !empty( $comments) ){
  echo '<ul class="reset-box-model no-bullets">';
    foreach($comments as $comment) :?>
      <?php // var_dump($comment);?>
      <li class="flex flex-middle">
        <div class="comment-cover">
          <?php echo get_avatar(  $comment->comment_author_email,38,null,$comment->comment_author); ?>
        </div>
        <div class="comment-info">
          <p class="comment-content"><a class="secondary-link" href="<?php echo esc_url( get_comment_link($comment->comment_ID) );?>" rel="nofollow"><?php echo $comment->comment_content;?></a></p>
          <p class="comment-meta"><?php $date=date_create($comment->comment_date);
echo date_format($date,"Y 年 m 月 d 日");?></p>
        </div>
      </li>
    <?php endforeach;
  echo "</ul>";
} else {
  echo '<p>';
  esc_html_e( 'Sorry, no posts matched your criteria.','info' );
  echo '</p>';
}

CSS代码就自己写了哈。

发表回复

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