Last active
October 3, 2024 09:58
-
-
Save lagenceoueb/d0f4a2936bbfe7537b65527c51785d21 to your computer and use it in GitHub Desktop.
Add a star review system on a php based page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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