Guest User

Untitled

a guest
Oct 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. $posts_count = 5; // The number of posts
  3. $days_range = 7; // To fetch posts published during the last 7 days
  4. $title_length = 40;
  5. $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);
  6. var_dump($result);
  7. foreach ($result as $topten) {
  8.     $postid = $topten->ID;
  9.     $title = $topten->post_title;
  10.     if(strlen($title) > $title_length){
  11.         $title = substr($title, 0, $title_length) . '...';
  12.     }
  13.     $commentcount = $topten->comment_count;
  14.     if ($commentcount != 0) {
  15.     ?>
  16.     <li class="clearfix"><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
  17.     <?php }
  18. }
  19. ?>
Add Comment
Please, Sign In to add comment