Last active
December 28, 2015 17:56
-
-
Save ashleyfae/5494ea56da3b7e9b9c5f to your computer and use it in GitHub Desktop.
Display UBB stars inside the Loop in your theme
This file contains 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 if ( have_posts() ) : ?> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php | |
/* | |
* You must start this code inside The Loop. | |
*/ | |
$rating = new UBB_Rating(); | |
/* | |
* This gives you the rating in a text-based format | |
* such as: | |
* five-stars | |
* four-half-stars | |
* three-stars | |
* ...and so on. This might be useful if you want to | |
* use the stars in a CSS class name. | |
*/ | |
$rating_text = $rating->rating; | |
/* | |
* This gives you the rating in a numerical format like: | |
* 5 | |
* 4.5 | |
* 3 | |
* ...and so on. | |
*/ | |
$rating_number = $rating->get_numerical_rating(); | |
/* | |
* This gives you your rating in standard UBB format. | |
* This is the star format you've specified in your UBB | |
* options panel. | |
*/ | |
$rating_stars = $rating->get_rating(); | |
/* | |
* This gives you the rating in Font Awesome HTML markup. | |
* Sample HTML output for 3.5 stars would be: | |
* <span class="star_rating"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-full"></i><i class="fa fa-star-o"></i></span> | |
* Notice how this shows 5 stars total: 3 that are filled in, 1 half star, and 1 "empty" star (to make it clear it's 3.5 out of 5). | |
*/ | |
$rating_fa = $rating->get_font_awesome_stars(); | |
/* | |
* Here's an example of how you'd actually display one | |
* of the above variables. | |
*/ | |
echo $rating_stars; | |
?> | |
<?php endwhile; ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment