Most Viewed post by category, tags and archives in wordpress

Using WP-PostViews plugin we can display most viewed 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 viewed books by category vice.

Code:

<div id=”sidebar”>

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

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

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

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

<ul>

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

</ul>

<?php endif; ?>

</div>

<?php }?>

</div>

WP-PostViews 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:

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

  4. Go to ‘WP-Admin -> Settings -> PostViews’ to configure the plugin.
View Stats (With Widgets)
  1. Go to ‘WP-Admin -> Appearance -> Widgets
  2. The widget name is Views.
View Stats (Outside WP Loop)
  • To Display Least Viewed Posts
  • Use:

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

    The first value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The second value you pass in is the maximum number of post you want to get.

    Default: get_least_viewed(‘both’, 10);

  • To Display Most Viewed Posts
  • Use:

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

    The first value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The second value you pass in is the maximum number of post you want to get.

    Default: get_most_viewed(‘both’, 10);

  • To Display Least Viewed Posts By Tag
  • Use:

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

    The first value you pass in is the tag id.
    The second value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The third value you pass in is the maximum number of post you want to get.

    Default: get_least_viewed_tag(1, ‘both’, 10);

  • To Display Most Viewed Posts By Tag
  • Use:

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

    The first value you pass in is the tag id.
    The second value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The third value you pass in is the maximum number of post you want to get.

    Default: get_most_viewed_tag(1, ‘both’, 10);

  • To Display Least Viewed Posts For A Category
  • Use:

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

    The first value you pass in is the category id.
    The second value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The third value you pass in is the maximum number of post you want to get.

    Default: get_least_viewed_category(1, ‘both’, 10);

  • To Display Most Viewed Posts For A Category
  • Use:

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

    The first value you pass in is the category id.
    The second value you pass in is what you want to get, ‘post’, ‘page’ or ‘both’.
    The third value you pass in is the maximum number of post you want to get.

    Default: get_most_viewed_category(1, ‘both’, 10);

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

    <?php query_posts(‘v_sortby=views&v_orderby=desc’) ?>

    Or pass in the variables to the URL:

    http://yoursite.com/?v_sortby=views&v_orderby=desc

    You can replace desc with asc if you want the least viewed 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: