wordpress无插件实现Gravatar头像功能:[1]

2025-04-21 16:50:08

1、找到需要插入最新留言的地方。一般的博客类的都在首页侧边栏,打开模板文件(你的网站/wp-content/theme/当前模板)打开sidebar.php

2、在最新留言处添加<?phpglobal $wpdb;$sql = "SELE觊皱筠桡CT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,14) 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 post_password = '' AND user_id='0' ORDER BY comment_date_gmt DESC LIMIT 10";$comments = $wpdb->get_results($sql);$output = $pre_HTML;foreach ($comments as $comment) {$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 32).strip_tags($comment->comment_author).":<br />" . " <a href=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"on " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";}$output .= $post_HTML;echo $output;?>这段代码显示日志作者及浏览者的留言

3、还有段代码不显示作藤舔趾贶者留言。为 什么要去掉作者的留言呢,道理很简单,一般留言都显示在侧边,如果设置显示10条留言,正好有10位浏览者留言,而作者可能在同一时间内分别进行回复,结 果就是侧边显示的留言全部是作者自己的,不利于站长及时查看是否有新留言并回复。代码如下:<?phpglobal $wpdb;$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,14) 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 post_password = '' AND user_id='0' ORDER BY comment_date_gmt DESC LIMIT 10";$comments = $wpdb->get_results($sql);$output = $pre_HTML;foreach ($comments as $comment) {$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 32).strip_tags($comment->comment_author).":<br />" . " <a href=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"on " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";}$output .= $post_HTML;echo $output;?>

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢