Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Helper function check if value is int or float
- function is_decimal($val){
- return is_numeric( $val ) && floor( $val ) != $val;
- }
- if ( !function_exists('my_stars_rating')){
- function my_stars_rating( $content ){
- global $post;
- $stars_count = get_post_meta($post->ID,'total_score', true);
- if ($stars_count){
- ob_start() ?>
- <h3 class="ctr-title"><?php printf( __('The rating for this post is %s', 'textdomain'), $stars_count );?></h3>
- <ul class="ctr-stars-list">
- <?php
- if ( is_decimal($stars_count) ){
- for ($i = 1; $i <= ($stars_count); $i++){
- echo '<li class="ctr-star"><i class="fas fa-star" aria-hidden="true"></i></li>';
- }
- echo '<li class="ctr-star"><i class="fas fa-star-half" aria-hidden="true"></i></li>';
- } else {
- for ($i = 1; $i <= $stars_count; $i++){
- echo '<li class="ctr-star"><i class="fas fa-star" aria-hidden="true"></i></li>';
- }
- }
- ?>
- </ul>
- <?php
- return ob_get_clean();
- }
- if ( is_single() ){
- return $content.$stars_count;
- }
- }
- }
- add_filter('the_content', 'my_stars_rating');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement