Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Created December 19, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwkyyy/f8997d3fdbea4bb36941ad7d4ef20064 to your computer and use it in GitHub Desktop.
Save rwkyyy/f8997d3fdbea4bb36941ad7d4ef20064 to your computer and use it in GitHub Desktop.
Show empty stars onwards (CSSIgniter response)
//Display the rating on a submitted comment.
add_filter( 'comment_text', 'ci_comment_rating_display_rating' );
function ci_comment_rating_display_rating( $comment_text ) {
if ( $rating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
$stars = '<p class="stars">';
for ( $i = 1; $i <= 5 ; $i ++ ) {
if ( $i <= $rating ) {
$stars .= '<span class="dashicons dashicons-star-filled"></span>';
} else {
$stars .= '<span class="dashicons dashicons-star-empty"></span>';
}
}
$stars .= '</p>';
$comment_text = $comment_text . $stars;
return $comment_text;
} else {
return $comment_text;
}
}
@vicso-name
Copy link

This is a cool solution. Please tell me how to do that if the average rating is, for example, 4.5, the fifth star is displayed by half.

@rwkyyy
Copy link
Author

rwkyyy commented Aug 12, 2020

The initial & updated post about this, you can find here

It also includes the half star rating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment