借用之前转载的《Typecho打造点赞功能(教程)》,思路是一样的,能做个点赞,也能做个踩帖的功能,然后通过点赞和总人数的比例推算一个评分标准
比如某一篇文章,支持顶贴2人,踩帖1人,总数3人,那么评分(满分为10分)为2*10/3=6.6分
如图所示
教程
右上角的星级评定代码
HTML
<div class="product-star5"></div>
css
.product-star10 { background: url(../../spzac/img/star10.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star9 { background: url(../../spzac/img/star9.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star8 { background: url(../../spzac/img/star8.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star7 { background: url(../../spzac/img/star7.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star6 { background: url(../../spzac/img/star6.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star5 { background: url(../../spzac/img/star5.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star4 { background: url(../../spzac/img/star4.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star3 { background: url(../../spzac/img/star3.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star2 { background: url(../../spzac/img/star2.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star1 { background: url(../../spzac/img/star1.png) no-repeat 0px center; height: 30px; background-size: 90px; }
.product-star0 { background: url(../../spzac/img/star0.png) no-repeat 0px center; height: 30px; background-size: 90px; }
通过文章id查询支持数和踩帖数,通过支持*10/(支持数+踩帖数)=评分等级
最后通过round(),去掉小数点保留整数匹配到上面说到的css样式即可