半下午+半晚上的功夫,终于搞定~
wordpress2.8的后台可以启用gravatar了
但总觉得头像丑了点。。
于是自己动手
显示头像的函数在functions.php中:<?php echo get_avatar($comment, 64); ?>
原来想找到get_avatar()的源码,失败
想找找$comment的定义,也失败
于是自己摸索着写了代码:
<?php
echo “<img src=’/wp-content/themes/fusion/images/wow/”.getNum($comment).”.jpg’ class=’avatar’ />”;
?>
getNum()是一个hash
function getNum($comment)
{
$ss = $comment->comment_author_email;
$hash = 0;
$n = strlen($ss);
for ($i = 0; $i < $n; $i++)
{
$hash += ($hash <<2 ) + ord($ss[$i]);
}
return ($hash % 81)+1;
}
刚开始一直得负数。。发现是移位太狠了。。数字改小后OK
图片就81张,所以是模81
函数的位置也要看下。。一不小心就会出现reclaim
感觉win下文件查找太麻烦了
还是grep好用啊。。。
#1 by icycandy on November 18th, 2009
This is excellent!!
#2 by admin on November 19th, 2009
水,好水。。
#3 by FloydRhonda on June 6th, 2010
If you are willing to buy a car, you will have to receive the home loans. Furthermore, my brother usually uses a financial loan, which is the most reliable.