I Need Discipline Free WordPress Installation - Start Your Blog Today!
Powered by MaxBlogPress  

Join The IND Mailing List Today!

The I Need Discipline mailing list is the ideal way to be kept well informed about the very latest posts that are published on this blog. You will also receive bonus articles that are not available on this blog and various freebies!

ghy

We respect your privacy!

Display Your Most Commented Posts Without A Plugin

by Dean Saliba on March 22, 2011 · Wordpress Tutorials


I haven’t kept on top of my promise to become more regular with my articles on this blog, I’ve relied heavily on guest posts and I’m hoping to correct this very soon. In the mean time I thought I would answer a common request and post a useful trick for displaying the most popular posts on your blog.

If you look at the top of this blog you will see a section that is called ‘The Most Popular Articles On IND Today’ this is a list of the seven most commented on posts on my blog. People often ask me how I managed to do this.

Well here it is.

You simply insert the following code into your sidebar, or whichever file you wish (header, footer, etc), don’t forget to change the amount of posts to show, I have seven listed but you might want more or less.

[sourcecode language='css']

The Most Popular Articles On IND Today

    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) { ?>

  • casters fell off my chair. Everything seems to be going wrong at the moment!

    Article by

    Dean Saliba is a freelance writer, professional blogger, media enthusiast, dirty football player and huge professional wrestling fan who covers a wide range of subjects and niches including, making money online, traffic generating, pro wrestling, blog reviews, football, how-to guides, music, internet marketing and more.

    Connect with me on Facebook | Twitter | LinkedIn | Google+ | Website

    Dean has written 372 awesome articles for us at I Need Di$cipline

    Write for us a Guest Post!

{ 3 comments… read them below or add one }

Abdul Rehman (1 comments) March 26, 2011 at 2:06 pm

That’s a nifty little code. I had been weekly updating the popular posts list before I took it down because of the useless work involved. Now I need to figure out a way to get this as a sidebar widget. I guess I’ll need to tweak the widgets.php file or something. :P
Abdul Rehman recently posted..Higher Bounce Rate More MoneyMy Profile

Reply

Dean Saliba (1525 comments) March 28, 2011 at 9:04 pm

Thank you Abdul. Thanks for dropping by, you have an awesome blog. :)

I haven’t read this post completely (and I suck at PHP code) but would this be of interest to you?

Reply

Business Loans (67 comments) June 13, 2011 at 6:45 pm

It would also be nice if there is a list of your recent blog posts at the side to make it complete. ;)

Reply

Leave a Comment

CommentLuv badge

Previous post:

Next post: