are you saying that you just want to replace the text [Rating: 4/5] with an image of 4 stars?
<strong>Overall</strong>: <img src='path/to/your/images/<?php echo $overall_value_formatted ?>.png'>
I am saving that as a last resort, but the reason I want to stick to the plugin is because it standardises the numbers and formats them for me without having to go through the entire db and doing that.
Any ideas how I could do that?
what do you mean without having to go through the db? you’re already going through the db to get the values, you can create 1 image with all 5 stars turned off, and one with all 5 turned on, overlay 2 divs, and just make the “on” div be the width needed for the set # of stars.
i.e. if the $overall_value is 4.2 and the overall image width is 100 wide, you create a div that’s 150 wide with the blank stars background, and inside it, create a div that’s ceil($overall_image_width/($overall_value/100)) (aka 150/(42/100) or 150/.42 giving you a width for the 2nd div of 42
so, it shows 150 pixel blank star image and over top of that, shows 42 percent of a 150 pixel wide filled star image.
so, something like:
<?
$image_width = 150;
$star_width = ceil($image_width/($overall_value/100));
?>
<div style="position:relative;width:<?=$image_width?>px;background-color:blue">
<div style="position:absolute;top:0px;left:0px;width:<?=$star_width?>px;background-color:red;overflow:hidden"> </div>
</div>
granted, that code uses background colors rather than images, but the concept is the same
Ooh I’ve never though of it like that. I was thinking I’d have to manipulate and standardise each number before calling the desired picture.
I guess I could try working with that since it would improve load time due to the use of less plugins etc..
But the problem is, I am having the same problem with other shortcodes which the theme provides. I would’ve been tempted to just go with that solution but I am relying on shortcodes that the theme provides too.
guess I’m confused, you said earlier that you made the plugin, so you control the shortcodes and how they act.. so what is the problem?
Okay, so the plugin is the code over at http://pastebin.com/FWB3qbcP which I am working on.
It works for except for one problem.
When I call for shortcodes (I am using [Rating] from http://wordpress.org/extend/plugins/mombly-review-rating/ AND [toggle] as provided by the theme) they don’t get converted to what they ought to be, instead, they show up as the raw text
Is that any better at explaining it?
so, are you saying that you are trying to use other plugin’s shortcodes within your plugin?
if you are, then instead of doing [Rating] you should be doing:
<?php echo do_shortcode('[Rating]'); ?>
hopefully that will help you 🙂
Noo unfortunately all that is just echo the text
I go excited there for a second since your suggestion is something I haven’t come across before.
I tried playing around with the filter orders but that had no effect either.
did you ever try calling the function that the shortcode calls rather than calling the shortcode itself?
I just went through mombly’s code and the function is mombly_rating_addRating() but I don’t see how I can call it through my plugin.
Putting mombly_rating_addRating(“2/5”) causes an error :S
try reading the other thread you opened on this.. I answered it there
instead of:
<strong>Overall</strong>: [Rating:<?php echo $overall_value_formatted ?>/5]
you can try doing something like:
<?php
$line = '<strong>Overall</strong>: [Rating:'.$overall_value_formatted.'/5]';
$line = mommbly_rating_addRating($line);
echo $line;
?>
It produces a fatal error with regards to the function not being defined.
I figured it was an issue with the plugin since other shortcodes which I tried with do_shortcode() worked fine.
So I’ve found an alternative plugin (http://jonathanspence.com/software/wordpress-plugins/xavins-review-ratings/) which seems to be working just fine.
Thank you so much for your help and introducing me to the do_shortcode() function.