Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Created December 19, 2018 15:10
Show Gist options
  • 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;
}
}
@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