Pod Ratings

Version 1.1.0 added 4 months ago by tokyograph

1.1.0 Notes

Modified the "rating/vote" page to avoid conflicts with pre/post-save helpers

About this Package

This package lets you easily add a rating field to any Pod type. It comes with a display helper for an AJAX-based five-star rating system, but you can customize it using your own display helper. The implementation for the star rating is similar to the one used at http://podscms.org/

The package consists of:
- [Pod] pod_rating (used for storing the rating statistics)
- [Pod] pod_rating_vote (used for storing the votes)
- [Page] rating/vote (used for processing the votes)
- [Display Helper] rating_star5 (default helper for star ratings)

To add ratings to a Pod type, just add a new PICK column with pod_rating as the related pod. That's it! The package will handle the rest, including creating pod_rating records for each pod.

To display the ratings, use the display helper rating_star5. For example, if you name the column 'rating,' then your template can use the line:

{@rating, rating_star5}

If you use the pod_helper function, you must provide the field name. For example:

$Record->pod_helper('rating_star5', $Record->get_field('rating'), 'rating');

You can include as many ratings on a single page as you want. You can even have multiple ratings fields on the same pod. The display helper will only include the necessary Javascript and CSS styling a single time.

----------Setup----------
1) Import the package using the Package Manager.

2) In the "rating/vote" Page, there are two configurable variables:
$require_wp_user (restricts voting to logged-in users, default is false)
$allow_vote_change (lets people change their votes, default is true)

3) At the top of the "rating_star5" helper, set $require_wp_user to the same value as above.

4) In the <style> section of the "rating_star5" helper, modify the URLs for the background images to point to the ratings image you are using. You will need to upload the image to your WordPress installation, either in your theme folder or somewhere else. The default "rating_star5" helper is designed for use with the image at http://podscms.org/wp-content/themes/uproot-v2/img/icons/stars20.png

----------Customization----------
You can use any other image you want for the ratings, but you will have to modify the CSS appropriately.

If you want to use a range of values besides 1-5, you can change the $vote_min and $vote_max variables in the "rating/vote" Page.

If you want to create your own display helper, the "rating/vote" page requires four variables:
'pod' (the name of the pod type)
'id' (the table row id of the pod type)
'field' (the name of the rating field)
'vote' (the numerical value of the rating)