Forums › Forums › Search & Filter Pro › Sort Results by star rating
- This topic has 36 replies, 2 voices, and was last updated 8 years ago by Anonymous.
-
Anonymous(Private) November 16, 2016 at 10:03 pm #70783
Managed to get it to show the number by adding true after the code…
while ($query->have_posts()) { $query->the_post(); ?> <div> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h3> <p><br /><?php the_excerpt(); ?></p> <?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?> <h6>Average Rating: <?php echo get_post_meta( get_the_ID(), 'ratings_average', true ); ?> Stars</h6> <p></p> <p><small></small></p> </div> <hr /> <?php
And I have added some text. It doesn’t actually show the 5 stars, that would be better if you know how to do that as in your example websites. At the moment it shows Average Rating: 5 Stars for example, just in text.
Alex
Trevor(Private) November 17, 2016 at 4:30 pm #70898Try this as the code to output stars:
<span id="post-ratings-<?php get_the_ID();?>" class="post-ratings"><?php $star_rating = get_post_meta( get_the_ID(), 'ratings_average', true ); for ( $star_count = 1, $star_count <= 5, $star_count++) { $star_status = "on"; if ( $star_rating < $star_count ) { $star_status = "off"; } ?><img id="rating_<?php get_the_ID();?>_<?php echo $star_count;?>" src="http://www.golf-library.com/wp-content/plugins/wp-postratings/images/stars/rating_<?php echo $star_status;?>.gif" alt="Star" title="Star"><?php } ?></span>
Anonymous(Private) November 17, 2016 at 5:54 pm #70938Done that but the page now doesn’t load…
<h6>Average Rating: <span id=”post-ratings-<?php get_the_ID();?>” class=”post-ratings”><?php
$star_rating = get_post_meta( get_the_ID(), ‘ratings_average’, true );
for ( $star_count = 1, $star_count <= 5, $star_count++) {
$star_status = “on”;
if ( $star_rating < $star_count ) {
$star_status = “off”;
}
?>_<?php echo $star_count;?>” src=”http://www.golf-library.com/wp-content/plugins/wp-postratings/images/stars/rating_<?php echo $star_status;?>.gif” alt=”Star” title=”Star”><?php } ?></span></h6> <p>Votes: <?php echo get_post_meta( get_the_ID(), ‘ratings_users’, true ); ?><p>The indents have gone if that makes any difference?
-
AuthorPosts