Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I run a news and review website using wordpress and I need some help, when reviewing items on our site we do a score our of 100% on our custom fields, the custom field is titled "Score" and in the box we write the % ie. 95%...

What we want to do is change the colour of the score on the website dependant on what the score is ie. 1%-25% would be red, 26%-50% orange, 51%-75% light green and then 76%-100% in heavy green thus giving the users a colour chart to follow alongside the score.

The code I'm using at the moment to pull the custom field data is as follows...

<div class="reviewscore"><?php $values = get_post_custom_values ("Score"); echo $values[0]; ?></div>

If anyone could help me with this I would be extremely grateful!

Thanks for your time.

share|improve this question
1  
This question is a PHP question, not a WordPress specific question, since no WP knowledge is required to fix it. Also you didn't mention what form your percentage is, e.g. 0.5, 50%, 50 – Tom J Nowell Aug 28 '12 at 10:17
Hi @TomJNowell , the %'s go up in 0.5 increments for instance 75.5% So will my question go unanswered here because it's php related? – Dave Burns Aug 28 '12 at 11:31
It should be moved elsewhere, like the main SO site, because it's a general PHP question rather than one that requires WordPress expertise. Are you saying that if I printed $values[0] I would get "75.5"? Or are you saying I would get "75.5%"? – Tom J Nowell Aug 28 '12 at 12:07
It would print 75.5% – Dave Burns Aug 28 '12 at 12:17
okay, you should save it as 75.5 instead, and just append % when printing. Basically, remove the % then if(percentage < 25){ use colour X } else if (percentage < 50){ use colour Y } else if (percentage < 75 ){ use colour Z } else { use that other colour } – Tom J Nowell Aug 28 '12 at 13:17

closed as off topic by Michael, Stephen Harris, Tom J Nowell, Wyck, kaiser Sep 13 '12 at 15:34

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.