目前东莞SEO用的是萧涵模板,Wordpress侧边栏都是使用代码而不是插件,所以要调用最新评论并显示Gravatar头像也只能使用代码,也不能使用小工具。
打开模板文件夹下的sidebar.php文件,找到合适的位置插入以下代码
[php] <div class="block comment"><h3>最新评论</h3>
<ul>
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,comment_post_ID, comment_author,comment_author_email,comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,15) 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 = ” 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($comment, 32)."" . $comment->comment_author . ": <br /> <a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"". $comment->comment_author. ":" . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= $post_HTML;
echo $output;
?>
</ul>
</div>[/php]
还需要修改萧涵模版文件夹下的CSS文件 style.css 将
[css].sidebar .block.comment{}
.sidebar .block.comment li{background:url(images/ico-com.png) 0 -245px no-repeat;padding-left:20px;color:#777;border-bottom:1px #d0d4c8 dashed;}
.sidebar .block.comment li a{color:#436206;}[/css]
修改为
[css].sidebar .block.comment{}
.sidebar .block.comment li{clear:both;color:#649315;margin-top:5px;padding:0 0 3px 0;border-bottom:1px #ddd dashed;}
.sidebar .block.comment li img{float:left;margin:5px 8px 0 0 ;}[/css]
使用这段代码可以完美支持Wordpress 3.3.2 ,效果就在右边显示(现在偶看使用的是wordpress3.4.2 by:10-25)。
目前Gravatar服务器访问正常,速度也很快,我就没有使用Gravatar的本地缓存插件,因为插件开启后,头像无法及时更新,影响用户体验。
点击查看萧涵主题修改全记录
你是怎么解决的,我用的是bbshuang 4.0的主题,按照方法操作,侧边栏不显示最新评论,只显示评论者的头像,我的是wordpress程序建的站,
Gravatar头像我早就在该网站设置成功了,可是在你博客右侧的最新评论里为啥显示的不是我设置的头像呢?
我在后台的评论看到你的Gravatar头像已经设置成功,但是偶看博客前台侧边栏的Gravatar头像没有显示正确,估计是这个博文里面的代码问题。
到底是wp版本的问题,还是萧寒主题的问题呢?
到底是wp版本的问题,还是萧寒主题的问题呢?
这中方法也试过了,也是不显示的!!
侧边栏完全不使用小工具才能显示这个,如果使用小工具就使用插件WP-RecentComments
这中方法也试过了,也是不显示的!!
侧边栏完全不使用小工具才能显示这个,如果使用小工具就使用插件WP-RecentComments