MOin on Jul 13, 2010 | Tips & Tutorials

Show Your Blog’s Most Popular Posts Without Using Any Plugin

Delicious

To show your visitors Most Popular Posts from your blog you can use the following code. This code snippet will gather a list of top posts based on comments count on that post. More comments to a post makes it more popular.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<h2>Popular Posts</h2>
<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
 
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

You can add this code to your Sidebar.php if you want to show Most Popular Post List in your blog’s sidebar. If you want to show more than 5 posts at a time simply find comment_count DESC LIMIT 0 , 5″); in above code and change ‘5‘ to 10 or 15.

Stumble it Digg it Vote on Reddit Add to delicious
Tweet it Share on facebook Add to Technorati Float it

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply


You can submit your free wordpress theme in WP skinner user submitted themes gallery to get Downloads and popularity. Its Free! ​ ​ Submit your Theme

View All >>

About | Contact | Submit your Theme
© 2010 WP Skinner | Powered by WordPress Top ^