MENU



  • WORM MAGIC
  • Head In the Clouds
  • The Carnivorous Perils of Space by MrRocks
  • THAI MASK by xWECHTERx
  • Trouty Mouth – Half Salamander
  • Elemento by nicebleed83
  • Extinct by nicebleed
  • Dead_Space by Studio8Worx
  • myspace angle by youmaykillthebride
  • Ready 2 Fall by putra666

  • POPULAR POSTS


  • Submit News

  • FRIENDS

  • Display Your Popular Posts In WordPress Without A Plugin


    .

    Posted by Daniel in Wordpress on September 7th, 2010 with 30 Comments

    Display Popular Posts In WordPress Without A Plugin

    Whilst working on nenuno version 3.0 I have been adding new features across the board! One being able to show which your most commented posts in your sidebar without the need for a plug-in. As a bonus it will grab your featured image to generate a small thumbnail to make it look more attractive.

    Before I start this tutorial be sure to check out one of the most visited resources here at nenuno “Adding Post Thumbnails To WordPress 3.0” which will get the ball rolling with working with featured images.

    The PHP

    <ul id="popular-comments">

    First lets create a WordPress Query! Setting it to look for the posts with the most (rhymes!) comments. I have selected 10 but it can be any number you desire.

    <?php
    $pc = new WP_Query('orderby=comment_count&posts_per_page=10');
    ?>

    WordPress will check what posts are most popular.

    <?php while ($pc->have_posts()) : $pc->the_post(); ?>
    <li>

    The posts with the highest comment count will be displayed, side by side with a small thumbnail taken from the featured image (If no featured image is available it will display nothing)

    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(10,10)); ?></a>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>

    Add a few basic details relating to the article/resource. I have choosen the posts author and the date it was published.

    <p>Posted by <strong><?php the_author() ?></strong> on the
        <?php the_time('F jS, Y') ?> with
        <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p>
    </li>

    Finish off the loop.

    <?php endwhile; ?>
    </ul>

    Now to bundle it all together and paste into a sidebar widget! Be sure that your widgets are PHP enabled. I use Executable PHP widget, but that is down to personal preference. You can also hard code this feature straight into your theme.

    <ul id="popular-comments">
    
    <?php
    $pc = new WP_Query('orderby=comment_count&posts_per_page=10'); ?>
    
    <?php while ($pc->have_posts()) : $pc->the_post(); ?>
    <li>
    
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(10,10)); ?></a>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    
    <p>Posted by <strong><?php the_author() ?></strong> on the
        <?php the_time('F jS, Y') ?> with
        <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p>
    </li>
    
    <?php endwhile; ?>
    </ul>
    

    Styling

    Some basic CSS is required to make this fit with the rest of your themes design. I have commented which each style does.

    #popular-comments { list-style:none; width:360px; } /*Set the width of your popular post*/
    
    #popular-comments li { overflow:auto; margin:10px 0px; border-bottom:1px solid #E6E6E6; padding-bottom:5px; } /*Style your post list, I have opted for a bottom border which is 1 pixel thick.*/
    
    #popular-comments li img { float:left; margin-right:10px; border:4px solid #EEEEEE;} /*Give your thumbnail taken from the featured image a nice border! A thick border adds to the effect.*/
    
    #popular-commentss li a { text-decoration:none; font-weight:bold; color:#1e292b;} /*Give your active links a bit of color.*/
    
    #popular-comments li p { margin-top:10px; }

    End Result

    Now your all done! Here is my end result, what does yours look like? Post below!

    my-popular-posts

    On a side note, we are looking for some of your contributions! Got something creative to share with the community? Now is the perfect time to get involved! Learn more about Contributing.

    WordPress is one of the recognized things these days and people have found ways to customize it, however another way to improve your overall knowledge is getting the 000-105 certification. This and other certifications are known worldwide as they test all the capabilities of the person, the 642-972 is no different in any manner. If at this point you are thinking how will you clear it, then the answer is the 70-290 dumps, which are for the respective certification, however other dumps for all certifications are there, they are not dumps, they are actually a ticket to ace the exam.


    Short url: Display Your Popular Posts In WordPress Without A Plugin - http://bit.ly/KmnuEZ

    Posted in Wordpress using the Tags: , , , ,

    Related Posts



    I love all things fantasy and you see that within in the content I produce for nenuno creative.

    See all posts by Daniel


    • Twitter
    • Design Bump
    • Web Blend
    • Facebook
    • Design Float
    • Reddit
    • Delicious
    • Stumble
    • Icon
    • Icon
    • Digg It
    • RSS

    Network Posts



    You can leave a response, or trackback from your own site,

    30 Responses to “Display Your Popular Posts In WordPress Without A Plugin”

    1. Great article about Popular Posts, keep up the goo work!

    2. Paul says:

      looks good, I do something similar but I tend to use timthumb and add it that way :)

    3. That’s Great Work , Thanks Daniel !

    4. Bob says:

      Hi,

      thanks,

      but how to display most popular posts based on number of views ?

    5. Awesome post! Really well done. I am always looking for wonderful WordPress tutorials to share with my readers and your post is one of the clearest I have seen. Again, thank you very much! Really like your blog. Really good!

    6. That’s great article on wordpress Thanks buddy

    7. Rohit says:

      thanks for the great info……..

    8. This is an awesome plugin! I will really benefit from this. Thanks.

    9. AB-track says:

      could u make tutorial about how to order most viewed posts !!

      • bob says:

        Hi,

        I’m not the only who need help/tutorial to display/order most VIEWED posts.

        AB-track is also interested ! Great !

        thanks in advance.

    10. Excellent! Can you please make a WordPress plugin for this.

    11. Chris says:

      This is probably a stupid question, but I’m a total WordPress noob. How do I create a WordPress Query?

      The widget looks great by the way. Looking forward to getting it up on my site!

    12. javy says:

      how would you make the plugin only choose posts from the last month?

    13. Robi says:

      Excellent! it gona be nice

    14. Rodrigo says:

      Where I Begin? What is the php I have to modify? (step1)

    Trackbacks


    Leave a Reply


     

    All content, such as illustrations, photos, resources and tutorials are copyright to their respective owners.

    nenuno creative is a trademark of nenuno design & development network and any content or resources originally created by nenuno can't be used without permission.