Wordpress Popular Posts


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <h2>Popular Posts</h2>
  2. <ul>
  3. <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
  4. foreach ($result as $post) {
  5. setup_postdata($post);
  6. $postid = $post->ID;
  7. $title = $post->post_title;
  8. $commentcount = $post->comment_count;
  9. if ($commentcount != 0) { ?>
  10.  
  11. <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
  12. <?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
  13. <?php } } ?>
  14.  
  15. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.