一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

WordPress不显示博主自己的评论

时间:2022-06-25 18:57:36 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

最新评论


  

         $show_comments = 10; //评论数量
      $my_email = "[email protected]"; //获取博主自己的email
      $i = 1;
      $comments = get_comments('number=200&status=approve&type=comment'); //取得前200个评论,如果你每天的回复量超过200可以适量加大
      foreach ($comments as $rc_comment) {
       if ($rc_comment->comment_author_email != $my_email) {
        ?>
        
  • comment_author_email,24); ?>
    comment_author.":".$rc_comment->comment_content),0,45,"..."); ?>

  •          if ($i == $show_comments) break; //评论数量达到退出遍历
        $i++;
       } // End if
      } //End foreach
      ?>
      
 
 

其中第6句用get_bloginfo函数不知道为什么获取不到邮箱字段,懒得研究了,直接填邮箱,用mb_strimwidth函数实现了截断,D2默认的评论调用方式如下。。。
templates/recentcomment.php

 代码如下 复制代码

global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID,
   comment_author, comment_date_gmt, comment_date, comment_approved,comment_author_email,
   comment_type,comment_author_url,
   SUBSTRING(comment_content,1,12) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1'
   AND comment_type = ''
   AND comment_author != 'admin'
   AND post_password = ''
   ORDER BY comment_date_gmt DESC LIMIT 10";
 
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
   foreach ($comments as $comment) {
   $comment_author = strip_tags($comment->comment_author);
   $comment_content = strip_tags($comment->com_excerpt);
   $permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
   $post_title = $comment->post_title;
   $comment_date = $comment->comment_date;
   $email = $comment->comment_author_email;
   $output .= '

  • '.get_avatar($email, 24).'
    '.''.$comment_content.'»'.'
    '.'Post: '.$comment_date.'
  • '  ;
       }
    $output .= $post_HTML;
    $output = convert_smilies($output);
    echo $output;
    ?>

    templates/sidebar.php

     代码如下 复制代码


      

    最新评论


      include('templates/recentcomment.php'); ?>
     

     

    热门栏目