Drupal Example Multi-axis Rating

Here is how to do it:

[1] Create a “product” node type. Create a product page, add a fivestar hidden field. Create a product node.

[2] Create a “review” node type with a node reference field pointing to product, and two fivestar rating fields one called “reliability” and another “value”. Create a review node for one user to review and rate the product. One user can only review a product once.

[3] Copy in the theme folder from node.tpl.php to node-product.tpl.php. Add this piece of code:

  1 <?php
  2 $reliability_rating = votingapi_select_results(array('content_id' => $node->ni    d, 'tag' =>'reliability', 'function' => 'average'));
  3 print '<div><strong>Reliability Rating:</strong>';
  4 print theme('fivestar_static', $reliability_rating[0]['value'], '5');
  5 print '</div>';
  6 $value_rating = votingapi_select_results(array('content_id' => $node->nid, 'ta    g' =>'value', 'function' => 'average'));
  7 print '<div><strong>Value Rating:</strong>';
  8 print theme('fivestar_static', $value_rating[0]['value'], '5');
  9 print '</div>';
 10 ?>

Now from the product node, the average rating can be seen.

For further information, read the documentation on drupal.org.


About minghuasweblog

a long time coder
This entry was posted in All, LAMP and Drupal and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s