给Typecho主题做一个顶踩功能评分功能

借用之前转载的《Typecho打造点赞功能(教程)》,思路是一样的,能做个点赞,也能做个踩帖的功能,然后通过点赞和总人数的比例推算一个评分标准

比如某一篇文章,支持顶贴2人,踩帖1人,总数3人,那么评分(满分为10分)为2*10/3=6.6分

如图所示

给Typecho主题做一个顶踩功能评分功能

教程

右上角的星级评定代码

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样式即可

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索