Subscribe via Feedburner Flickr Images Youtube Profile LinkedIn Profile
Dev4Press

Comments integration #1

Thumbnail for Comments integration #1

Integrating both post’s standard and multi ratings into comment, so that the post reader can add comment about the topic and assign rating (or review) for that post along with the comment, is very easy. Due to the current limitations of WordPress this can’t be done automatically, and it requires making changes to the theme files. I will use default WordPress theme for example. Also, my Starscape theme can be used as a example of the integration.

This first step allows you to add active rating block into comment area. With this block comment author can set a rating before submitting the comment. Same principle is used for both standard (single) and multi ratings. These ratings will be added to the post. So, in this case you might need to disable automatic insertion of rating in the post, or to set it inactive. This will be discussed later. You need to add this block before the textarea in the comment form (comments.php, line 83), to unsure that the rating is visible to both logged in users and visitors.


<?php if (defined("STARRATING_INSTALLED")) : ?>
<p><?php wp_gdsr_comment_integrate_standard_rating(); ?>
<label for="url"><small>Rating</small></label>
</p><?php endif; ?>

First row checks if the GD Star Rating is installed. If it is, a new comment form element is added. You only need to make a call to a integration funtion. Function added in this example will insert standard, single rating block. This call can be changed, because this function supports few parameters that will be used to change the stars set for that block. If you leave it the way it is now, default rating block set in the settings panel will be used. Full list of parameters for each function you can find included with the plugin in the info folder, or click here.

If you want to add multi ratings, the function will require some more parameters to ensure that everything works. You need to include multi set id you want to use and template for rendering. I have created templates map with detailed graph of dependencies for each template type. For this type of rendering plugin uses MRI (Multi Rating Integration) template. If you don’t set the template, default one will be used. Following code with add multi rating and will use multi set with ID 4.


<?php if (defined("STARRATING_INSTALLED")) : ?>
<p><?php wp_gdsr_comment_integrate_multi_rating(4); ?>
<label for="url"><small>Rating</small></label>
</p><?php endif; ?>

Multi ratings also has a number of other parameters you can use to change the the stars set and size used for rendering.

All ratings saved through comments will be added to the post rating. So, if you want post only to display rating result and not to allow voting you need to change rating rules for that post (for each post through widget on post edit page, or via articles panel for the GD Star Rating), or to insert the post using the function or shortcode. Functions that are used to render rating block into post have $allow_vote parameter you need to set to false. List of these functions is also available in the info pages.

When the list of comments are displayed, you can show rating saved with each comment.  Next article will describe that second integration part.

GD Star Rating
loading...

Share this:

del.icio.us DiGG Google StumbleUpon Google Buzz Microsoft Live MiXX RSS PDF
Comments integration #1, 7.3 out of 10 based on 116 ratings

13 Responses to “Comments integration #1”

  1. Ninanoki | May 28, 2009 at 12:11 AM

    that’s what i was really waiting for;)thank you so much Millan!

    GD Star Rating
    loading...
  2. Mark | May 28, 2009 at 9:33 PM

    Hi Milan,

    Thanks it is working, multirating in the comments. Nice! Is is possible to call different multirating ID’s is the comments?

    Say for the post ‘laptop’ containing a readonly of the multiblok ‘laptop’ plus the multiblok in the comment. And then for an other post ‘mobile phone’ the multiblok ‘mobile phone’ in the comment.

    Greetz

    GD Star Rating
    loading...
    • MillaN | May 28, 2009 at 9:47 PM

      Multi ratings can be set on the category base. There will be more work to improve on this. But to use it now in the comments integration, you ust use some IF blocks to include different multi set ids.

      GD Star Rating
      loading...
  3. Jason Tremblay | May 28, 2009 at 11:44 PM

    When I do this comment integration, it seems that users are allowed an additional vote each time they comment. Is there any way I can allow a user to have only one vote, even if they leave multiple comments?

    GD Star Rating
    loading...
    • MillaN | May 28, 2009 at 11:49 PM

      This is very complicated issue, and so far there no easy way to prevent multiple comments from the same user/visitor. I will try to find some way to solve this, so if anyone has any suggestion for this I will appreciete it.

      GD Star Rating
      loading...
      • David | June 16, 2009 at 5:41 PM

        The standard way to do this is to log the IP of each comment, and then when a post_id/comment_ip match is found, display the stored rating instead of the voting block.

        This would probably have to be done in the template with code, but a function such as “gd_rating_exists()” or something could be used to check to see if the IP has commented yet.

        You should make this a setting, since this will prohibit 2 people in the same company (using a NAT and a single IP) from voting. Another way is to required login, but someone could register many time if they really wanted to. IP works best most of the time.

        GD Star Rating
        loading...
        • MillaN | June 16, 2009 at 6:11 PM

          Well, you can disable IP checking. Also, you can limit ratings to registered and logged in users, and then IP is not relevant, but only user id.

          GD Star Rating
          loading...
  4. Greg | May 29, 2009 at 8:23 PM

    Is it possible to add ratings to an author page?

    GD Star Rating
    loading...
    • MillaN | May 29, 2009 at 9:07 PM

      All ratings are post/page and comment based. Author page is not actually not a page, but an archive.

      GD Star Rating
      loading...
  5. kiralık eşya deposu | June 3, 2009 at 1:10 PM

    Is it possible to add ratings to an author page?

    GD Star Rating
    loading...
    • MillaN | June 3, 2009 at 1:43 PM

      Ratings are post/page related. Aauthor page is an archive.

      GD Star Rating
      loading...
  6. Ed | June 11, 2009 at 9:39 AM

    Hi Millan,

    Great info and thanks for it.

    When I use this code it does indeed put the multi ratings in the comment, but I then loose multi ratings in the post section.

    Is there a way to have both?

    GD Star Rating
    loading...
    • Ed | June 11, 2009 at 9:45 AM

      Actually, please disregard I must be doing something wrong on the live site, because i done it locally with mamp and its working there, maybe i should re-install.

      p.s is it possible also for small tutorial on how to deactivate voting. thx.

      GD Star Rating
      loading...

Comments are closed.