Show Top 10 Posts in WordPress Without a Plugin
Wordpress is a great blogging tool and many plugins are available to do just about everything. But having 100 plugins will make your site crawl and will annoy your users.
This tutorial will show you how to add some simple code to show the top ten posts for various metrics anywhere on your blog
Instructions
Top Posts By Comments
The following code gets posts from the database and orders them by the amount of comments they have and selects the top 10.
If you want to change the amount of posts displayed change LIMIT 0 , 10 to another number (0 is the first post and 10 is the last)
If you wish to choose the least posted comments then change DESC to ASC
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 7");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) { ?>
<a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?>
<?php } }?>
The last but one line echos the title of the post as a link. To use this code just copy and paste it where you wish the code to appear
Most Recent Posts
an oldy but a goody. The code to show the ten most recent posts that have been posted on your blog
Just change showposts=10 to another number to change the amount of posts shown
The last but one line echos the title of the post as a link. To use this code just copy and paste it where you wish the code to appear
<?php query_posts('showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); ?>">
<?php the_title(); ?></a>
<?php endwhile;?>
Most Viewed Posts
I decided to include this one even though there is no code for it. WordPress does not save any information on how many pages are viewed therefore it is impossible to show this information without using a plugin or some 3rd party monitoring software
If you have found a way using only code please let me know!


Sample Config for WordPress Running on Varnish 2.1
Are you using 32 bit or 64 bit Office 2010?
Have Outlook 2010 Automatically Close a Message After Replying or Forwarding
How to Start Outlook 2010 in a Different Folder
Do you get Error Code 80071392 Using Windows Live Messenger?
How To Image, Sysprep and Deploy Windows 7 a Complete Guide – Using sysprep and Imagex
How to Disable Auto Renewal for Xbox Live
Installing Windows 7 From a USB Stick From Windows XP (Bootable USB) 
Great tips, thank you. View counts can be done with only code! I’m using Justin Tadlock’s entry-views extension in my theme without a plugin
http://devpress.com/blog/entry-views-extension/
//Frankie
Oh and for anyone else reading this…just an FYI, I do believe ‘showposts’ has been deprecated in favor of ‘posts_per_page’
//Frankie
Views count will add lots of cpu usage the more post you have, but yeah it’s possible.
thanks for the tips .
Two small observations :
1. recent posts has a wp function wp_get_recent_posts();
$recent_posts = wp_get_recent_posts();
2. your comment count will also show revisions (not published) posts if blog has less than 10 commented posts .