Wordpress Post Popularity
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>·</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.





