Skip to content

Instantly share code, notes, and snippets.

@lagenceoueb
Last active October 3, 2024 09:58
Show Gist options
  • Save lagenceoueb/d0f4a2936bbfe7537b65527c51785d21 to your computer and use it in GitHub Desktop.
Save lagenceoueb/d0f4a2936bbfe7537b65527c51785d21 to your computer and use it in GitHub Desktop.
Add a star review system on a php based page
<?php
/**
* Generates the star rating based on the number of reviews.
*
* @param int $reviews The number of reviews to calculate the star rating.
* @return string The HTML representation of the star rating.
*/
function stars( $reviews )
{
$stars = '';
$stars .= '<div class="addsell-star">';
for ($i = 0; $i < 5; $i++) {
if ($i < $reviews && $reviews - $i >= 1) {
$stars .= '<span class="dashicons dashicons-star-filled"></span>';
} elseif ($i< $reviews && $reviews - $i < 1) {
$stars .= '<span class="dashicons dashicons-star-half"></span>';
} else {
$stars .= '<span class="dashicons dashicons-star-empty"></span>';
}
}
$stars .= '</div>';
return $stars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment