Jan 312010

I’m putting together a ratings and review website to compare electronic cigarettes (eCigs) and eCig suppliers. The site is built on wordpress using the GD Star Ratting plugin. For those of you who may not know about ecigs they are mechanical cigarette like devices which use an atomizer to vaporize nicotine. The main appeal, aside form being “smokeless” (that is in theory you could smoke one in an airport), is they’re a bit cheaper.

eCig products are in a precarious legal standing with the FDA and there is huge variance of the quality amoung the various eCig models.  As a result making an informed purchasing decision is next to imposable.  eCig Press is a resource for anyone interested eCigs and offer reviews of products and suppliers.

I’m using GD Star Ratting to allow visitors to post reviews and rate eCig products and eCig suppliers. This is done by integrating GD Star Rating into the native wordpress comment mechanism. Here’s a few notes someone may find helpful.

Right out of box I noticed the page level permissions were broken. I could not, for example, set thumb voting on comments and remove star ratting from the comments (to vote on the comments themselves). Fortunately I found this solution which fixed the permissions problem without too much fumbling around.

The next issue was allowing visitors to include a star rating value along with there comment / review. The GD Star rating website has some information which helped me get started. As noted in the article though the situation is more complicated when using threaded comments which, for now, eCig Press does.

The solution here is create your own custom comments template. As noted in the article wp_list_comment accepts the name of a custom callback function as a parameter. You can then used this callback function to build a customized comment form which includes your rating field.

You can define a custom call back like so:

<?php wp_list_comments('type=comment&callback=comment_raiting'); ?>

Then you just need to create the custom function (comment_rating in my case). Here’s an example of the function used by eCig Press at the time of this writing:

function comment_rating($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='48',$default='' ); ?>

         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

      <div class="comment-meta commentmetadata">
      <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
	  <?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a>
	  <?php edit_comment_link(__('(Edit)'),'  ','') ?></div>

	<?php if (defined("STARRATING_INSTALLED")) : ?>
    <div>
    <?php  wp_gdsr_comment_integrate_standard_result(get_comment_ID()); ?>
    </div>
    <?php endif; comment_text(); ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>

The following function call in the above block is what inserts the actual rating widget:

wp_gdsr_comment_integrate_standard_result(get_comment_ID());

So there you have it, a pretty sweet way to let visitors to your site contribute ratings along with comment reviews using wordpress and the incredible GD Star Rating plugin.

Leave a Reply

(required)

(required)

© Aaron Wolf. Unauthorized use and/or duplication of this material, including photos and videos, without express and written permission from Aaron Wolf is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Aaron Wolf and acwolf.com with appropriate and specific direction to the original content.

Log in