Tuesday, 4 June 2013

  • How to - Showing Popular Posts Without A Plugin



    Just paste the following code on your sidebar.php file. To change the number of displayed posts, simply change the 5 on line 3.

    <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>

  • 0 comments:

    Post a Comment

    Copyright @ 2013 Wordpress Joomla Fans.