Function tạo rating star sử dụng dashicon từ wordpress: với function này anh chị không phải nhúng fontawesome hay bất cứ icon nào khác mà sử dụng ngay icon star trong star. Sau đây là code ae copy về xài , ae nhớ chố $rating_averating nếu xài 5 star thì không $rating_averating/2, hiện tại function dưới là mình làm cho 10 stars mà hiển thị 5 star nên $rating_averating/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
function the_star_show($star){ $rating_averating = $star; $rating_averating = $rating_averating/2; $rating_averating_round_floor=floor($rating_averating); $build_stars = ''; switch ($rating_averating_round_floor) { case '1': if($rating_averating > 1.5): $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-half" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; else: $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; endif; break; case '2': if($rating_averating > 2.5): $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-half" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; else: $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; endif; break; case '3': if($rating_averating > 3.5): $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-half" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; else: $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; endif; break; case '4': if($rating_averating > 4.5): $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-half" data-index="5"></span>'; else: $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; endif; break; case '5': $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-filled" data-index="5"></span>'; break; default: $build_stars='<span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="1"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="2"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="3"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="4"></span><span class="eupro-seo-star-rating dashicons dashicons-star-empty" data-index="5"></span>'; break; } $rating='<div class="eupro-seo-out" > <div class="eupro-seo-star-rating-wrap ">'.$build_stars.'</div> </div>'; echo $rating; } |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress