Moving the Ratings Stars

Currently the 5 star rating system is at the top of the directory pages, I would like to have all of it, or at the very least, the option to rate it, down in the section to leave a review so an end user can rate it when they leave a review.

Ive tried some cut and past of the code from ratings.php but the closest I got was a drop down menu of rating (didnt recognize the span or div maybe) but it wouldn’t submit.

what is the best way to have this option in the leave a review section?

  • Troy
    • Site Builder, Child of Zeus

    Neuroticartist, I’m using the single-listing.php page to style how the rating and other information is laid out on each listing.

    In my file the following code is where the ratings star system is located:

    <div class="listingRating">
    <?php if ( !is_user_logged_in() ) : ?>
    <?php echo '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to rate item.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post->ID ) ) ) ) . '</p>'; ?>
    <?php else: ?>
    <?php do_action('sr_rate_this'); ?>
    <?php endif; ?>
    </div>

    You’ll need to create a style for “listingRating” in your CSS. Something like this:

    .listingRating {
    float:right;
    width:270px;
    min-height: 200px;
    border:1px solid #ccc;
    padding: 20px;
    margin: 0 0 10px 0;
    }

    Hope this is helpful. :slight_smile:

  • neuroticartist
    • Design Lord, Child of Thor

    this seems to be showing on the page but for some reason I am still getting the drop down menu and not the star rating and it is not saving the rating. Strange thing is, I get the star rating shown on my regular other blog pages but the directory pages show the drop down. (I put it in the themes comments.php)

    Perhaps it has to do with something in my single-listing.php since my other pages arent using this?

  • neuroticartist
    • Design Lord, Child of Thor

    it does not, I also tried that to see if the div formatting was stopping something. Strangely enough, its only on the directory listing pages. I wanted to add it to my comments.php because the rest of the site would also benefit from the rating system and oddly enough it works no problem on pages not using the single-listing.php. the other pages are using single-property.php, which I am assuming is the same kind of page but written out to display property info

    a property page not using the directory single-listing.php

    http://houstonhomeandlandsource.com/property/51192-wilderness-ln/

    a directory listing page using the code from the single-listing.php file included with the directory theme (copied over to the theme root)

    houstonhomeandlandsource.com/listings/sog-armory-inc/

  • neuroticartist
    • Design Lord, Child of Thor

    now that’s strange, you are absolutely correct. I wonder why that is? Why would being a logged in admin stop it from showing the stars? Strange but even logged in as a regular user it seems to work. thoughts?

    Thanks for your help! I really appreciate it

    Roz

  • Troy
    • Site Builder, Child of Zeus

    Hard to troubleshoot from my end. I would use Firebug or Chrome’s Inspect Element to view the ratings — while logged in as the admin.

    You could also try to disable and re-enable the Directory plugin. Just disabling it won’t help because you need it on to see your listings. However, turning it off and on can fix weird caching issues. It’s odd but I’ve seen this work before.

    Not sure I’m actually helping but you’re welcome anyhow. WPMU is great for working though challenges. Just doing my part to kick back. :slight_smile:

  • Arun Basil Lal
    • New Recruit

    Hey Guys,

    I tried this with a login and everything seems to the working fine. I see that there is the rating drop down (which is weird), but didn’t you mention that you moved some code around from ratings.php?

    Isn’t that creating the rating drop down? Removing that will make things better, right?

    (I might have missed something from the conversation above, please fill me up if I do).

    Looking forward to it.

  • neuroticartist
    • Design Lord, Child of Thor

    Sorry for the confusion Arun, I had originally copied some code from ratings.php which I thought was the problem. The code we are currently using is what troycdunn posted in the very first reply at the top of this page.

    It works great excepot for when you are logged in as admin. when your logged in as admin, it only shows a drop down menu and doesnt save the rating. I tried this on different browsers (and currently using firefox)

    If you are wanting to look into this further, and If you are unable to recreate this issue, let me know and I will PM you admin credentials to my site

  • Arnold
    • El Macho WP

    If you look at the code in render_rate_this() the first thing it does is check if you’ve already rated that listing. If so it displays the stars of your vote rating.

    If you haven’t voted yet it displays a dropdown with the vote choices.

    Now that’s for the brain dead no javascript guys. If you have javascript there is a jquery-ui-stars.js file that changes the look to the hover stars. So it appears that something is interferring with the jQuery running the stars display.

    In this case it’s because you have two rating items with the same ID. id=”rat”. It finds the first one and looks no further because there aren’t supposed to be two identical ids ever.

  • Troy
    • Site Builder, Child of Zeus

    My guess is that there is a jQuery conflict.

    I’ve been working on some something unrelated today and needed to add in a call to the newest version of jQuery. When I add in the code below, my stars become radial buttons and the voting becomes a drop down.

    <script src="http://code.jquery.com/jquery-latest.js"></script>

    If I comment that out, I get stars; in both the average rating display and the voting.

  • neuroticartist
    • Design Lord, Child of Thor

    ok so what would you suggest as a work around, if I rename the 2nd id=”rat” to id=”rat2″ would it fix that issue or would it no longer work correctly?

    If I removed the option to rate from the top of the page so the rating shows up top but not the option to rate it yourself, and only use that at the bottom, would it solve it being that there is now only a single instance of it?

  • Arnold
    • El Macho WP

    The script addresses by ID, so just renamimg doesn’t do it. Having only one instance would work.

    The real fix would be to rewrite it with classes instead of IDs so that more than one would be affected by the same call.

    Might have side effects though so it would need ot be looked at carefully.

  • neuroticartist
    • Design Lord, Child of Thor

    Thanks Arnold, that did the trick! I didnt make any changes to the code I put in the comments.php but I did backup my directory folder and install your new beta 2.1.2 and even logged in as admin, the star rating works both at the top of the page and at the bottom in the comments/re views section.

    should I change anyting in the code I added? I used the code Troy posted at the top of this page.

    Thanks again!

    Roz

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.