• asgsoft

    (@asgsoft)


    Hey guys,

    I’ve been stuck with this issue for a wile and need some help.

    So I’ve made a basic wordpress plugin which creates a short tag “[review id=1]”

    This short tag would then query a mysql database and display the info for the review with $id 1 which works fine.

    The problem is, part of the review calls on another plugin, http://wordpress.org/extend/plugins/…review-rating/ to display the rating as in stars by displaying “[Rating:4/5]”

    However, rather than displaying the picture, “[Rating:4/5]” is written down whereas normally I’d get 4 stars.

    Is there anyway I can fix that?

    What I have so far is on: http://pastebin.com/FWB3qbcP

    Cheers

Viewing 15 replies - 1 through 15 (of 17 total)
  • luckdragon

    (@luckdragon)

    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'>

    Thread Starter asgsoft

    (@asgsoft)

    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?

    luckdragon

    (@luckdragon)

    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

    Thread Starter asgsoft

    (@asgsoft)

    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.

    luckdragon

    (@luckdragon)

    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?

    Thread Starter asgsoft

    (@asgsoft)

    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?

    luckdragon

    (@luckdragon)

    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]'); ?>

    Thread Starter asgsoft

    (@asgsoft)

    yes! 🙂

    luckdragon

    (@luckdragon)

    hopefully that will help you 🙂

    Thread Starter asgsoft

    (@asgsoft)

    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.

    luckdragon

    (@luckdragon)

    did you ever try calling the function that the shortcode calls rather than calling the shortcode itself?

    Thread Starter asgsoft

    (@asgsoft)

    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

    luckdragon

    (@luckdragon)

    try reading the other thread you opened on this.. I answered it there

    luckdragon

    (@luckdragon)

    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;
    ?>
    Thread Starter asgsoft

    (@asgsoft)

    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.

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘an issue with a wordpress plugin calling external shortcodes’ is closed to new replies.