目前东莞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的本地缓存插件,因为插件开启后,头像无法及时更新,影响用户体验。
点击查看萧涵主题修改全记录
这个好,能用代码还是用代码改。只是担心每次wp升级,在后台更新系统之后代码还要重新添加。
确实是这样,很多插件无法跟上wordpress更新的脚步。
这个好,能用代码还是用代码改。只是担心每次wp升级,在后台更新系统之后代码还要重新添加。
确实是这样,很多插件无法跟上wordpress更新的脚步。
我想在文章後顯示作者的gravatar
請問這個代碼:get_the_author_email
該如何對下面的語法做修改?
‘;if (function_exists(‘get_avatar’) &&get_option(‘show_avatars’)) {echo get_avatar($comment,32);};echo ‘
在合适的位置放入代码 <?php echo get_avatar( get_the_author_email(), ’60’ );?> ,即可,60是头像的像素大小,可以自由修改。
感謝您的回覆,我有試過直接使用您提供的語法,但是會發生:
Parse error: syntax error, unexpected T_LNUMBER, expecting ‘,’ or ‘;’ in /home/loveitw/public_html/2be/wp-content/themes/ineo1.2/single.php on line 32
可能是因為佈景主題的關係,所以我在寫法上都必須這樣寫才可以順利運行:
‘;the_author_posts_link() ;echo ‘
‘;the_author_description() ;echo ‘
Website – More Posts
=====
那麼如何將<?php echo get_avatar( get_the_author_email(), ’60’ );?>
編寫成類似下面的寫法呢:
‘;the_author_posts_link() ;echo ‘
‘;the_author_description() ;echo
不知道我表達的是否清楚,也感謝您的回應,真的幫我很大的忙,謝謝您~
阿~我打的語法都被直接顯示了,
我是否可以直接用EMAIL跟您請教呢?
真的是麻煩您了
我想在文章後顯示作者的gravatar請問這個代碼:get_the_author_email該如何對下面的語法做修改?’;if (function_exists(‘get_avatar’) &&get_option(‘show_avatars’)) {echo get_avatar($comment,32);};echo ‘
在合适的位置放入代码 <?php echo get_avatar( get_the_author_email(), ’60’ );?> ,即可,60是头像的像素大小,可以自由修改。
感謝您的回覆,我有試過直接使用您提供的語法,但是會發生:Parse error: syntax error, unexpected T_LNUMBER, expecting ‘,’ or ‘;’ in /home/loveitw/public_html/2be/wp-content/themes/ineo1.2/single.php on line 32可能是因為佈景主題的關係,所以我在寫法上都必須這樣寫才可以順利運行: ‘;the_author_posts_link() ;echo ”;the_author_description() ;echo ‘Website – More Posts =====那麼如何將<?php echo get_avatar( get_the_author_email(), ’60’ );?>編寫成類似下面的寫法呢:’;the_author_posts_link() ;echo ”;the_author_description() ;echo不知道我表達的是否清楚,也感謝您的回應,真的幫我很大的忙,謝謝您~
阿~我打的語法都被直接顯示了,我是否可以直接用EMAIL跟您請教呢?真的是麻煩您了
刚试了下 不知为啥没效果
查看这一篇文章,还有视频:http://www.oukan.net/2012111021.html
刚试了下 不知为啥没效果
查看这一篇文章,还有视频:http://www.oukan.net/2012111021.html
我的也是这种情况:Gravatar头像在文章下面显示一切正常,就是边栏不显示评论图像,评论的什么也看不到。如果不用小工具,直接代码替换行不行?请问要用什么插件来实现了?
目前,偶看使用的就是代码,没有使用小工具和插件。
文章下面显示一切正常,就是边栏不显示评论图像,评论的什么也看不到。
如果启用小工具就无法使用代码来实现Gravatar头像,可以使用插件实现。
求救呀!按着您说的方法试了很多次了,还是一点效果都没有。直接就没反应。是不是还有其它地方也需要改的。我把您在QQ群里分享的sidebar.php上传覆盖了,都没有效果。什么原因,搞不明白了。
怎么还有vip样式啊
根据网友的评论条数来判断VIP等级的。
偶看,侧栏评论,如果屏蔽管理员的评论啊
在$sql这个语句里添加一个AND comment_author != ‘您的昵称’
我用了,评论名字和内容跟头像不在一排呀?
哦,搞好了,把你的CSS复制过去就好了。。你不厚道哇,CSS改了也不说下。。嘿嘿。。
这篇文章很早以前写的,现在加上CSS
Parse error: syntax error, unexpected T_STRING in /home/zyjfcom/domains/feng-jiao.com/public_html/wp-content/themes/xiaohan3/sidebar.php on line 73
出现这个错误了,是咋回事呢,求助博主了
您把代码放到哪里呢?会出现73行的错误。
我也是用的这个主题,拿去参考参考。。
这个代码对于Wordpress的主题是通用的。
Pingback: 萧涵主题修改全记录 | 偶看
还是不明白,楼主怎么弄出侧栏”最新评论”中头像+留言的效果啊?搞不定啊,博主说“打开模板文件夹下的sidebar.php文件,找到合适的位置插入以下代码 ”合适的位置是哪里啊?出错!求助一下
另外,在”小工具”里怎么调用啊?可以从左边拖一个“近期评论”,但是现实的还是wp默认的效果,出不来你网站的效果。
直接修改代码的,无法在小工具中调用。
插入在一个代码的结尾后 /div
博主,头像是怎么搞出来的啊??
按照文章的方法就可以弄出来了。
很好的功能,支持!
Gravatar头像很有功能性!
提示:Parse error: syntax error, unexpected T_STRING in D:\kankan\xampp\htdocs\wordpress\wp-content\themes\bbshuang 4.0\sidebar4.php on line 25 line25内容: $sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,comment_post_ID, comment_author,comment_author_email,comment_date_gmt line28行也提示错误: $output .= “\n”.get_avatar($comment, 32).”” . $comment->comment_author . ” : ID) . 30行就一个}符号也红条显示。博主解决一下吧
我目前用的主题用这个代码没有什么问题,你用的是bbshuang 4.0的主题,我这边测试下看看是不是主题的兼容性。
已经修正了问题,代码在复制到WP的编辑框的时候被自动修改了,CSS需要自行处理。
嗯 谢谢啦!已经可以用了!哈哈
会导致右边的无法显示
是出现什么样的提示?