WpCode.net

Daily Wordpress Code Snippet

How to Display most commented posts of specific year without plugin

| 3 Comments

Pin It

This snippet allow you to show the most commented posts list between to dates without plugins. This code gets a DB query, and you need to specify in the snippet the beginning date and the ending date.

You can publish directly in sidebar or wherever you want. Continue reading

<ul>
<?php
$result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN 'YEAR-MM-DD (start)' AND 'YEAR-MM-DD (end)' ORDER BY comment_count DESC LIMIT 0 , 10");

foreach ($result as $topten) {
    $postid = $topten->ID;
    $title = $topten->post_title;
    $commentcount = $topten->comment_count;
    if ($commentcount != 0) {
    ?>
         <li></li>
    <?php }
}
?>
</ul>

3 Comments

  1. Pingback: WordPress Code Snippets and Detailed Tutorials | eXpand yOur cReativity

  2. Pingback: 19 Useful Wordpress Snippets & Tutorials - Design Freebies

  3. Pingback: 21 Fresh WordPress Code Snippets and Detailed Tutorials : Web design

Leave a Reply

Required fields are marked *.

*