Advertisement
Barbareshet

Stars review based on custom field value

Jun 7th, 2020
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  $stars_count = get_post_meta($post->ID),'total_score', true);
  3. //check if value is int or float
  4. function is_decimal($val){
  5.  
  6.         return is_numeric( $val ) && floor( $val ) != $val;
  7.     }
  8. <?php if ($stars_count){ ?>
  9.                 <ul class="ctr-stars-list">
  10.                     <?php
  11.                     if ( is_decimal($stars_count) ){
  12.                         for ($i = 1; $i <= ($stars_count); $i++){
  13.  
  14.                                 echo '<li class="ctr-star"><i class="fas fa-star" aria-hidden="true"></i></li>';
  15.  
  16.                         }
  17.  
  18.                             echo '<li class="ctr-star"><i class="fas fa-star-half" aria-hidden="true"></i></li>';
  19.  
  20.                     } else {
  21.                         for ($i = 1; $i <= $stars_count; $i++){
  22.  
  23.                                 echo '<li class="ctr-star"><i class="fas fa-star" aria-hidden="true"></i></li>';
  24.  
  25.                         }
  26.                     }
  27.                     ?>
  28.                 </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement