Most Rated post by category, tags and archives in wordpress

Using WP-PostRating plugin we can display most rated post by category, tags and archives. It’s more useful to know the best one of that particular category, tags and archives. I am using this concept in my project (higginbothamsstore.com) to display most rated books by category vice.

Code:

<div id=”sidebar”>

<?php if(is_category() || is_single()){?>

<h3 id=”widgettitle”>Most Rated books in <?php single_cat_title(); ?> </h3>

<div id=”mainright” style=”width:99%;”>

<?php if (function_exists(‘get_most_rated_category’)): ?>

<?php $cat_ID = get_query_var(‘cat’);?>

<ul>

<?php get_most_rated_category($cat_ID,’post’,0,5); ?>

</ul>

<?php endif; ?>

</div>

<?php }?>

</div>

WP-PostRatings 1.50 For WordPress 2.8.x

preview

More Instructions

General Usage
  1. Open wp-content/themes/<YOUR THEME NAME>/index.phpYou may place it in archive.php, single.php, post.php or page.php also.
  2. Find:

    <?php while (have_posts()) : the_post(); ?>

  3. Add Anywhere Below It (The Place You Want The Ratings To Show):

    <?php if(function_exists(‘the_ratings’)) { the_ratings(); } ?>

    If you DO NOT want the ratings to appear in every post/page, DO NOT use the code above. Just type in [ratings] into the selected post/page content and it will embed ratings into that post/page only.

    If you want to embed other post ratings, use [ratings id=”1″], where 1 is the ID of the post/page ratings that you want to display.

    If you want to embed other post ratings results, use [ratings id=”1″ results=”true”], where 1 is the ID of the post/page ratings results that you want to display.

Displaying Comment Author Ratings
  1. Open wp-content/plugins/wp-postratings/wp-postratings.php
  2. Find:

    //add_filter(‘comment_text’, ‘comment_author_ratings_filter’);

  3. Replace:

    add_filter(‘comment_text’, ‘comment_author_ratings_filter’);

Note
  • To use PNG images instead of GIF images:
    1. Open wp-content/plugins/wp-postratings/wp-postratings.php
    2. Find:

      define(‘RATINGS_IMG_EXT’, ‘gif’);
      //define(‘RATINGS_IMG_EXT’, ‘png’);

    3. Replace:

      //define(‘RATINGS_IMG_EXT’, ‘gif’);
      define(‘RATINGS_IMG_EXT’, ‘png’);

  • WP-PostRatings will load ‘postratings-css.css‘ from your theme’s directory if it exists.
    • If it doesn’t exists, it will just load the default ‘postratings-css.css’ that comes with WP-PostRatings.
    • This will allow you to upgrade WP-PostRatings without worrying about overwriting your ratings styles that you have created.
Ratings Stats (With Widgets)
  1. Go to ‘WP-Admin -> Appearance -> Widgets
  2. The widget name is Ratings.
Ratings Stats (Outside WP Loop)
  • To Display Lowest Rated Post
  • Use:

    <?php if (function_exists(‘get_lowest_rated’)): ?>
    <ul>
    <?php get_lowest_rated(); ?>
    </ul>
    <?php endif; ?>

    Default: get_lowest_rated(‘both’, 0, 10)

    The value ‘both’ will display both the lowest rated posts and pages.

    If you want to display the lowest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the lowest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 lowest rated posts/pages.

  • To Display Lowest Rated Post By Tag
  • Use:

    <?php if (function_exists(‘get_lowest_rated_tag’)): ?>
    <ul>
    <?php get_lowest_rated_tag(TAG_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_lowest_rated_tag(TAG_ID, ‘both’, 0, 10)

    Replace TAG_ID will your tag ID. If you want it to span several categories, replace TAG_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the lowest rated posts and pages.

    If you want to display the lowest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the lowest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 lowest rated posts/pages.

  • To Display Lowest Rated Post In A Category
  • Use:

    <?php if (function_exists(‘get_lowest_rated_category’)): ?>
    <ul>
    <?php get_lowest_rated_category(CATEGORY_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_lowest_rated_category(CATEGORY_ID, ‘both’, 0, 10)

    Replace CATEGORY_ID will your category ID. If you want it to span several categories, replace CATEGORY_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the lowest rated posts and pages.

    If you want to display the lowest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the lowest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 lowest rated posts/pages.

  • To Display Highest Rated Post
  • Use:

    <?php if (function_exists(‘get_highest_rated’)): ?>
    <ul>
    <?php get_highest_rated(); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_rated(‘both’, 0, 10)

    The value ‘both’ will display both the highest rated posts and pages.

    If you want to display the highest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the highest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 highest rated posts/pages.

  • To Display Highest Rated Post By Tag
  • Use:

    <?php if (function_exists(‘get_highest_rated_tag’)): ?>
    <ul>
    <?php get_highest_rated_tag(TAG_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_rated_tag(TAG_ID, ‘both’, 0, 10)

    Replace TAG_ID will your tag ID. If you want it to span several categories, replace TAG_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the highest rated posts and pages.

    If you want to display the highest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the highest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 highest rated posts/pages.

  • To Display Highest Rated Post In A Category
  • Use:

    <?php if (function_exists(‘get_highest_rated_category’)): ?>
    <ul>
    <?php get_highest_rated_category(CATEGORY_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_rated_category(CATEGORY_ID, ‘both’, 0, 10)

    Replace CATEGORY_ID will your category ID. If you want it to span several categories, replace CATEGORY_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the highest rated posts and pages.

    If you want to display the highest rated posts only, replace ‘both’ with ‘post’.

    If you want to display the highest rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 highest rated posts/pages.

  • To Display Highest Rated Post Within A Given Period
  • Use:

    <?php if (function_exists(‘get_highest_rated_range’)): ?>
    <ul>
    <?php get_highest_rated_range(‘1 day’); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_rated_range(‘1 day’, ‘both’, 10)

    The value ‘1 day’ will be the range that you want. You can use ‘2 days’, ‘1 month’, etc.

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Most Rated Post
  • Use:

    <?php if (function_exists(‘get_most_rated’)): ?>
    <ul>
    <?php get_most_rated(); ?>
    </ul>
    <?php endif; ?>

    Default: get_most_rated(‘both’, 0, 10)

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Most Rated Post In A Category
  • Use:

    <?php if (function_exists(‘get_most_rated_category’)): ?>
    <ul>
    <?php get_most_rated_category(CATEGORY_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_most_rated_category(CATEGORY_ID, ‘both’, 0, 10)

    Replace CATEGORY_ID will your category ID. If you want it to span several categories, replace CATEGORY_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Most Rated Post Within A Given Period
  • Use:

    <?php if (function_exists(‘get_most_rated_range’)): ?>
    <ul>
    <?php get_most_rated_range(‘1 day’); ?>
    </ul>
    <?php endif; ?>

    Default: get_most_rated_range(‘1 day’, ‘both’, 10)

    The value ‘1 day’ will be the range that you want. You can use ‘2 days’, ‘1 month’, etc.

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Highest Score Post
  • Use:

    <?php if (function_exists(‘get_highest_score’)): ?>
    <ul>
    <?php get_highest_score(); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_score(‘both’, 0, 10)

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Highest Score Post In A Category
  • Use:

    <?php if (function_exists(‘get_highest_score_category’)): ?>
    <ul>
    <?php get_highest_score_category(CATEGORY_ID); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_score_category(CATEGORY_ID, ‘both’, 0, 10)

    Replace CATEGORY_ID will your category ID. If you want it to span several categories, replace CATEGORY_ID with array(1, 2) where 1 and 2 are your categories ID.

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 0 refers to the minimum votes required before the post get shown.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Display Highest Score Post Within A Given Period
  • Use:

    <?php if (function_exists(‘get_highest_score_range’)): ?>
    <ul>
    <?php get_highest_score_range(‘1 day’); ?>
    </ul>
    <?php endif; ?>

    Default: get_highest_score_range(‘1 day’, ‘both’, 10)

    The value ‘1 day’ will be the range that you want. You can use ‘2 days’, ‘1 month’, etc.

    The value ‘both’ will display both the most rated posts and pages.

    If you want to display the most rated posts only, replace ‘both’ with ‘post’.

    If you want to display the most rated pages only, replace ‘both’ with ‘page’.

    The value 10 will display only the top 10 most rated posts/pages.

  • To Sort Highest/Lowest Rated Posts
  • You can use:

    <?php query_posts($query_string.’&r_sortby=highest_rated&r_orderby=desc’) ?>

    Or pass in the variables to the URL:

    http://yoursite.com/?r_sortby=highest_rated&r_orderby=desc

    You can replace desc with asc if you want the lowest rated posts.

  • To Sort Most/Least Rated Posts
  • You can use:

    <?php query_posts($query_string.’&r_sortby=most_rated&r_orderby=desc’) ?>

    Or pass in the variables to the URL:

    http://yoursite.com/?r_sortby=most_rated&r_orderby=desc

    You can replace desc with asc if you want the least rated posts.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: