昨天晚上就是折腾这个到半夜三点,一开始就想错了,结果越弄越错,人都要崩溃了。今天下午摆弄优化网站的时候,才发现自己昨天晚上不知道错到哪里去了。
<h3><?php _e('Recent Comments'); ?></h3>
<ul>
<?php
global $wpdb;
$my_email = get_bloginfo ('admin_email');
$rc_comms = $wpdb->get_results("
SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content
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 comment_author_email != '$my_email'
ORDER BY comment_date_gmt
DESC LIMIT 10
");
$rc_comments = '';
foreach ($rc_comms as $rc_comm) {
$a = 'avatar/'.md5(strtolower($rc_comm->comment_author_email)).'.jpg'; // 頭像緩存用的
$rc_comments .= "<li><img src='" . $a . "' alt='' title='" . $rc_comm->comment_author
. "' class='avatar' /><a href='"
. get_permalink($rc_comm->ID) . "#comment-" . $rc_comm->comment_ID
//. htmlspecialchars(get_comment_link( $rc_comm->comment_ID, array('type' => 'comment'))) // 可取代上一行, 會顯示 cpage, 但較耗資源
. "' title='on " . $rc_comm->post_title . "'>" . strip_tags($rc_comm->comment_content)
. "</a></li>\n";
}
$rc_comments = convert_smilies($rc_comments);
echo $rc_comments;
?>
</ul>
使用:直接贴到sidebar.php即可使用。
上面是willin的7月20号最新重新优化过的带缓存头像代码,但是却没有加截断函数,所以只能通过CSS设定。
#sidebar .recentcomments img.avatar{width:16px;height:16px;float:left;position:relative;border:1px solid #ddd;margin:0 5px 0 0;padding:1px;}
#sidebar ul.recentcomments{list-style:none;padding-left:0;}
#sidebar ul.recentcomments li{margin:5px 0 0;line-height:20px;height:20px;overflow:hidden;}
但是这部分在chrome和火狐都测试通过,就是IE不行,无法截断,超出的字依然会全部显示,菜鸟求解。
之前找到的代码对于屏蔽管理员最新评论在3.01后就失效了,这次可以顺便一起解决了。
感谢zwwooooo的《带头像显示的最新评论代码 – 蛋疼篇 》 感谢 Willin的最新評論 Recent Comments
» 转载请注明来源:《带头像显示的最新评论代码》
» 本文的链接地址:http://www.yshe.net/post/1836.html


#sidebar li a {去掉position:relative}试试
这句是鼠标平移里面的。
删掉,最新评论就可以截断就没问题。
但是鼠标平移不行,无奈。
这句怎么改能说下不,我把他变成全局变量也不行,
纳闷为什么只影响IE,chrome就没关系
那就让li整体右偏移吧,单个控制a偏移而用position:relative的话就会有这个bug
如果要改的话还有个方法,就是在jquery里不要使用left来控制右偏移,用marginLeft来代替右偏移,这样就避免了使用position:relative
好。我试试,先3Q
OK搞定,就是平移的时候有点别扭。
你的博客也是这样写的?
恩,用left控制在opera下会有一个很大的跳动,所以用marginLeft了
。。。。你怎么不问我啊。。。
我也安了,还没在IE下测试。。。
就是这个问题啊
IE出现问题。chrome和火狐就没问题,无奈