Error   test

Wordpress Post Popularity

Posted August 12, 2006 at 10:08pm in Computers, Programming, Wordpress

For anyone wanting a popularity ranking for Wordpress posts that are also using the WP-Postviews plugin this is a solution. It isn’t the best version, but it does what I want. Someone has already created a popularity plugin, but it did not work for me and taking the time to make it work could not be justified.

$int_tpop = 0;
the_pop();

function the_pop() {
        global $wpdb, $int_tpop;
        $total_views = $wpdb->get_row("
                SELECT SUM(meta_value) as tviews
                FROM wp_postmeta WHERE meta_key = 'views'"
);
        $int_tpop = $total_views->tviews;
}

function return_pop ($views = 0, $total = 0) {
        $formatted = number_format((($views/$total)*100), 1, '.', ");
        $out = $formatted;
        echo ' <b>&middot;</b> '.$out.'% Popularity';
}

Enter this where you would like the popularity to be displayed.
<?php return_pop(trim(the_views(",FALSE)),$int_tpop) ?>

I placed the above code into my header template file and placed the last line of code in my post display file. If you have any problems please let me know.

  • Google
  • del.icio.us
  • Digg
  • Spurl
  • Facebook

2 Responses to “Wordpress Post Popularity”

  1. Hans Says:
    March 2nd, 2007 at 2:12 pm

    I thought displaying my popular posts another way. Would you find this reliable? I came up with it like : you create a category for e.g famous posts and you tell a plugins to rotate the posts in that category. This way it gives the author himself more control over which posts he thinks might need more exposure or would be more enjoyed. He will just need to drop any good posts in that category.

    Many people have been using popularity plugins but I didn’t really get convinced in choosing it since perhaps the results could be biased. Did it work efficiently on your side?

  2. Peter Manis Says:
    March 2nd, 2007 at 2:29 pm

    I think that would be a good alternative, for me I would use it for what you said, to give more exposure to certain posts. As a way to see which posts people actually visit from search engines or on the site in general it won’t give you the overall popularity.

    For example my post about picking a 20 or 22 inch monitor has 24 views as of this posting, but my post about the shortcut to drag bookmarking a site that was posted 4 days later has 32 views. So it lets you know what topics people are actually visiting and reading more about.

    It is pretty accurate because it is taking all of the views recorded and dividing the number of views for that post by that total number. I am basing popularity purely on the views of all posts individually compared to the views on that specific post. Right now I am at 21,877 views, and this has 374 views simply saying that 1.7% of the total pages and posts that are read on a single page include this page.

    I tried one of the other popularity plugins and it didn’t work for me. I do not know his algorithm, but I think this works pretty well in letting users know how much traffic out of the total traffic goes to that page. It just cant tell you how many people read it in the category pages or the home page.



Leave a Reply