WP-PostRatings 只显示评分结果方法

Kevin 杂记 511 次浏览 13条评论

WP-PostRatings 插件使用<?php if(function_exists('the_ratings')) { the_ratings(); } ?>代码添加评分功能,但这是一个完整模块。如果希望只希望显示评分结果,限制点击评分操作,可以使用<?php echo the_ratings_results( get_the_ID() ); ?>获取,多余文本在插件模板选项里删除。

另一个方法是直接从数据库获取评分数据输出,方便修改结构样式。在functions.php主题文件里添加下面代码。

function showRatings($id, $css_class = 'show-ratings') {
 global $wpdb;
 $path = plugins_url('wp-postratings/images/'.get_option('postratings_image'));
 $rating = $wpdb->get_var("SELECT AVG(rating_rating) AS rating FROM $wpdb->ratings WHERE rating_postid = $id");
 $i = 0;
 $html = '<div class="'.$css_class.'">';
 if (!empty($rating)) {
 while ($i < floor($rating)) {
 $html .= '<img src="'.$path.'/rating_on.gif" alt="" />';
 $i++;
 }
 if (round($rating, 1) == ($i+0.5)) {
 $html .= '<img src="'.$path.'/rating_half.gif" alt="" />';
 $i++;
 }
 }
 while ($i < 5) {
 $html .= '<img src="'.$path.'/rating_off.gif" alt="" />';
 $i++;
 }
 $html .= '</div>';
 return $html; 
}

然后使用<?php echo showRatings( get_the_ID() ); ?>代码调用。

评论列表

  1. #1

    hydroxychloroquine sulfate tabs https://hydroxychloroquine.webbfenix.com/

  2. #2

    dose for acyclovir herpes simplex https://www.herpessymptomsinmen.org/productacyclovir/

  3. #3

    ivermectin dosage humans https://ivermectin.webbfenix.com/

  4. #4

    starting dose of naltrexone https://naltrexoneonline.confrancisyalgomas.com/

  5. #5

    hydroxychloroquine clinical trial results https://hydroxychloroquine.mlsmalta.com/

  6. #6

    ivermectin dosing for scabies https://ivermectin.mlsmalta.com/

  7. #7

    keflex sinus infection dosage https://keflex.webbfenix.com/

  8. #8

    vidalista 5mg cost https://vidalista.mlsmalta.com/

  9. #9

    buy zentiva hydroxychloroquine https://hhydroxychloroquine.com/

  10. #10

    tadalafil dapoxetine reviews https://dapoxetine.confrancisyalgomas.com/

  11. #11

    50mg viagra pills http://droga5.net/

  12. #12

    erectile disorder 38 cfr
    buy erection pills
    erectile enhancement pills
    top erectile urologists in san francisco

  13. #13

    vidalista without doctor prescription reviews https://vidalista40mg.mlsmalta.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。