This hack is so cool and so simple, I expect anyone to run up to me and yell that this has been done before. I created a 'Top Posts' sidebar widget based on the widget that comes with any Worpdpress.com blog.
I know there are several widgets like this, but they all include their own statistics tracking. Mine is nothing more than an excerpt of the Dashboard widget that comes with the Wordpress.com Stats plugin.
For people not interested in technical details, here is a plugin file, that works as usual; Make sure you install the Wordpress.com Stats plugin first!
I said this hack was simple, here is way: The code is already there! I'm surprised Wordpress did not include the widget themselves. Lets have a look at stats.php:
Line 925-926:
foreach ( $top_posts = stats_get_csv( 'postviews', "days=$options[top]$csv_args[top]" ) as $post )
$post_ids[] = $post['post_id'];<?php foreach ( $top_posts as $post ) : if ( !get_post( $post['post_id'] ) ) continue; ?>
<p><?php printf(
$printf,
'' . get_the_title( $post['post_id'] ) . '',
// '' . $post['post_title'] . '',
number_format_i18n( $post['views'] )
); ?></p>
<?php endforeach; ?>