Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $posts_count = 5; // The number of posts
- $days_range = 7; // To fetch posts published during the last 7 days
- $title_length = 40;
- $result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN ".(date("Y-m-d H:i:s",strtotime(date('Y-m-j H:i:s')) - ($days_range * 24 * 60 * 60)))." AND ".date("Y-m-d H:i:s")." ORDER BY comment_count DESC LIMIT 0 , ".$posts_count);
- var_dump($result);
- foreach ($result as $topten) {
- $postid = $topten->ID;
- $title = $topten->post_title;
- if(strlen($title) > $title_length){
- $title = substr($title, 0, $title_length) . '...';
- }
- $commentcount = $topten->comment_count;
- if ($commentcount != 0) {
- ?>
- <li class="clearfix"><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
- <?php }
- }
- ?>
Add Comment
Please, Sign In to add comment