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.
Viewing 10 posts - 21 through 30 (of 37 total)
  • Anonymous
    #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
    #70823

    Hi

    Can you show me a link with a page that actually has stars instead? Might be able to do something for you.

    Anonymous
    #70856
    This reply has been marked as private.
    Trevor
    #70870

    Ah. Images. Yes, that can be done. Needs a bit of coding. I haven’t got right now, but later yes.

    Anonymous
    #70872
    This reply has been marked as private.
    Trevor
    #70898

    Try 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
    #70934

    Hi Trevor, where about do I paste the code?

    Trevor
    #70936

    Instead of this:

    <?php echo get_post_meta( get_the_ID(), 'ratings_average', true ); ?> Stars
    

    It should just give you five stars in a row.

    Anonymous
    #70938

    Done 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_&lt;?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?

    Trevor
    #70940

    Arrggghh. Can you edit that and put the code inside code tags?

Viewing 10 posts - 21 through 30 (of 37 total)