GD Star Rating is my favorite rating plugin for WordPress. Not only does it have just about every option you could ever need, I always use it because it just works.
Included in the rating plugin are several widgets and code examples you can use and Milan included has several pieces of code and lots of examples on his website.
If you just want a simple piece of code that lists the top 20 posts by combining user and visitor votes, here is a simple piece of script.
I used the code to put in a page template for a drinks website. The page lists the most popular drinks (as by voted by users and visitors) and it is always up to date.

The most popular drinks sorted by ratings
Here is the code you can put in a custom page template:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php global $wpdb; // include the $wpdb $query= "SELECT p.ID, p.post_title as title, visitor_votes + user_votes as total_votes, visitor_votes, user_votes FROM `".$wpdb->prefix."gdsr_data_article` da INNER JOIN $wpdb->posts p ON da.post_id = p.ID order by total_votes desc limit 20"; $results=$wpdb->get_results($query); // run the query on the database if ($results) { // if we have any results ?> <table><thead><tr><th>Position</th><th>Post</th><th>Points</th></tr></thead> <?php $position=0; // we set the position as 0, as we start every loop with increasing it by one foreach ($results as $toppost) { $position++; // see, I told you, we increase by one, so the first post will get position #1 echo "<tr><td>#".$plads."</td><td><a href='".get_permalink($toppost->ID)."'>".$toppost->title."</td><td>".round($toppost->total_votes)."</td></tr>"; } ?> </table> <?php } } // Thats it, easy, eh? ?> |
Put that piece of code in a custom page template and you can have a top 20 list that is always updated with your most popular content.
Note: In this example I have given registered users and visitors votes the same weight. If you wish to give registered users more weight you can tweak the mysql query.