— tomauger.com

Hacking GD Star Ratings for WordPress: inserting ratings in your theme

This is a continuation from a previous post that looks at custom development based on the GD Star Ratings plugin for WordPress.

You would think this would be the most highly documented feature – how to actually insert the ratings for a particular article right in your theme. Heck, maybe there’s a way to do it from the Admin panel that I haven’t even noticed, but I’m a back end kinda guy anyway. Here’s the full code. This one has been written to work within The Loop, but it’s trivial to modify it to work with a custom loop or query if you wanted:

$postRatingData = wp_gdsr_rating_article(get_the_ID());
gdsr_render_stars_custom(array(
    "max_value" => gdsr_settings_get('stars'),
    "size" => 12,
    "vote" => $postRatingData->rating
));

That’s basically it in a nutshell. Max Value is the “total” number of stars (eg: 5 out of 5), Size must be one of the default sizes ie: 12, 16, 20, 24 etc, Vote is the actual calculated result, which we got by passing the ID of the current post to wp_gdsr_rating_article.

  • http://ScoDal.com Scott Dallas

    The code got the stars to show up, but I can’t use them. I’m trying to force “GD Star Rating” to work with “FeedWordpress” so it might just be FeedWordpress giving me (more) grief

  • Tomaugerdotcom

    Hey Scott, sorry I’m not familiar with FeedWordPress. Do yourself a favour and take a look to see if you’re not throwing any JavaScript errors (Firebug is a great tool for that) – the GDStars should work just fine unless JavaScript is halted for some reason.

  • http://ScoDal.com Scott Dallas

    That’s okay, I appreciate your help and you’re so right when you say, “You would think this would be the most highly documented feature.” I had to Google forever and finally stumbled upon this code you can use to get Thumb rating working with FeedWordPress:

    It won’t let me display the code here so I put it in a txt file and uploaded it to my ftp: http://scodal.com/gdstarthumbs.txt

    Looking at that, do you have any idea how to switch that into the star rating? I’m trying to get it working on http://f.oodporn.com which updates the latest delicious food photos from as many of the top foodie blogs I could find (using FeedWordPress). But being able to rate the food makes the experience so much better! Thumbs up and down isn’t the worst, but I really wanted 5 or 10 star rating lol

  • http://www.tomauger.com tomauger

    Scott, can I suggest that you create a post over at http://wordpress.stackexchange.com ? That’s my personal go-to site for even the most esoteric questions. I’ll personally keep an eye out for the post and try to weigh in if I can, but you’ll hopefully get some real luminaries to offer their advice quicker than I could.

  • FrmJpn

    Really really helped me, thanks!! I definitely give more than 10 star if you’ve installed GD star rating on this page.

  • Josephhagen

    Thanks for posting this! Could you let me know if this code is correct?


    gdsr_settings_get(‘1′),
        “size” => 16,
        “vote” => $postRatingData->100
    ));
    ?>

  • Josephhagen

    [code]

    gdsr_settings_get('1'),
        "size" => 16,
        "vote" => $postRatingData->100
    ));
    ?>

    [/code]
     

  • Sba

    Scott, try to use the correct icons’ set (size=32 is not available). Use instead 12 px
    16 px
    20 px
    24 px
    30 px
    46 px
    wp_gdsr_render_article ($template_id=0, $read_only=false, $stars_set=”crystal”, $stars_size=30, $stars_set_ie6=””, $echo=true);

  • http://ScoDal.com Scott Dallas

    Hey Sba, thanks for taking the time to reply to me! I am going to try that out soon and see how it goes. You rock!

  • natewiley

    Tom, Thanks a lot for writing this little post 4 years ago lol.. Spent hours trying to figure out how to render custom stars! With a big help to this, finally figured out what I needed to do! Thanks again!