评论一直显示自己的头像,想解决这个问题很久了,一直没动力,现在趁着刚换vps有动力,抓紧折腾,完事以后又是很久很久的懒得折腾,D2主题默认的评论调用一个单独的文件做评论,实在看不懂sql,得了,重新折腾评论吧,新的修改后的评论调用如下,如果是D2主题的朋友,可以直接拿过去用,代码如下:
- <div class="recent-comments">
- <h3>最新评论</h3>
- <ul>
- <?php
- $show_comments = 10; //评论数量
- $my_email = "loveyouf@vip.qq.com"; //获取博主自己的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) {
- ?>
- <li><dl><dt><?php echo get_avatar($rc_comment->comment_author_email,24); ?><?php echo $comment_author; ?></dt><dd><h5><a href="<?php echo get_permalink($rc_comment->comment_post_ID); ?>#comment-<?php echo $rc_comment->comment_ID; ?>"><?php echo mb_strimwidth(convert_smilies($rc_comment->comment_author.":".$rc_comment->comment_content),0,45,"..."); ?></a></h5></dd></dl></li>
- <?php
- if ($i == $show_comments) break; //评论数量达到退出遍历
- $i++;
- } // End if
- } //End foreach
- ?>
- </ul>
- </div>
其中第8句用get_bloginfo函数不知道为什么获取不到邮箱字段,懒得研究了,直接填邮箱,用mb_strimwidth函数实现了截断,D2默认的评论调用方式如下:
templates/recentcomment.php
- <?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 .= '<li><dl><dt>'.get_avatar($email, 24).'</dt><dd><h5>'.'<a href="'.$permalink.'" title="'.$post_title.'">'.$comment_content.'»'.'</a></h5><small class="en">'.'Post: '.$comment_date.'</small></dd></dl></li>' ;
- }
- $output .= $post_HTML;
- $output = convert_smilies($output);
- echo $output;
- ?>
- </ul>
templates/sidebar.php
- <div class="recent-comments">
- <h3>最新评论</h3>
- <?php include('templates/recentcomment.php'); ?>
- </div>
原文转自:http://www.xj123.info/4606.html
新闻热点
疑难解答
图片精选