question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What happened to the rating_img_url?

See original GitHub issue

In V2 you guys had “rating_img_url” however in V3 or Fusion all you supply is the actual rating # via “rating” I’m currently using the following with fontawesome but its not the cleanest way by any means:

if($response->businesses[$i]->rating == '1') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '1.5') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star-half-o"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '2') {
  echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-  star-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '2.5') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-o"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '3') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '3.5') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-o"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '4') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i>';
} elseif($response->businesses[$i]->rating == '4.5') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-o"></i>';
} elseif($response->businesses[$i]->rating == '5') {
    echo '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>';
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
contempoinccommented, Apr 7, 2017

Recoded, and for anyone else out there that maybe wants to use it, here’s the final using the official rating images in WordPress, again it could probably be done cleaner but it works.

if($response->businesses[$i]->rating == '0') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_0.png" srcset="' . get_template_directory_uri() . '/images/stars/small_0@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '1') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_1.png" srcset="' . get_template_directory_uri() . '/images/stars/small_1@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '1.5') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_1_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_1_half@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '2') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_2.png" srcset="' . get_template_directory_uri() . '/images/stars/small_2@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '2.5') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_2_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_2_half@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '3') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_3.png" srcset="' . get_template_directory_uri() . '/images/stars/small_3@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '3.5') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_3_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_3_half@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '4') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_4.png" srcset="' . get_template_directory_uri() . '/images/stars/small_4@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '4.5') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_4_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_4_half@2x.png 2x" />';
} elseif($response->businesses[$i]->rating == '5') {
        echo '<img src="' . get_template_directory_uri() . '/images/stars/small_5.png" srcset="' . get_template_directory_uri() . '/images/stars/small_5@2x.png 2x" />';
}
1reaction
wattersocommented, Apr 7, 2017

Glad you figured something out! I took a crack at cleaning up your example. Consider testing it first, I haven’t done PHP in a while 😃

$float_rating = (float)$response->businesses[$i]->rating;
$has_half_star = ($float_rating * 10) % 10
$star_count = (int)$float_rating
if($has_half_star){
    echo '<img src="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '_half@2x.png 2x" />';
}else{
    echo '<img src="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '.png" srcset="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '@2x.png 2x" />';
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Video-on-Demand system for IPTV
exchange can happen without the other host's prior knowledge. ... filename, name, description, year, length, lang, rating, imgurl).
Read more >
Flutter Archives - CodeSource.io
... and once this happens, the variable can be promoted to a non-nullable value. ... productName, rating: products[index].rating, imgUrl: products[index].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found