Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <li id="meta" class="widget-container">
  2. <h3 class="widget-title"><?php _e( 'Popular Posts', 'twentyten' ); ?></h3>
  3. <?php
  4.     $pop_posts = 5;
  5.     $popularposts = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title,  COUNT($wpdb->comments.comment_post_ID) AS 'stammy' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' AND comment_status = 'open' GROUP BY $wpdb->comments.comment_post_ID ORDER BY stammy DESC LIMIT ".$pop_posts;
  6.     $posts = $wpdb->get_results($popularposts);
  7.     if($posts){
  8.         foreach($posts as $post){
  9.         $post_title = stripslashes($post->post_title);
  10.         $guid = get_permalink($post->ID);
  11.         $thumb = get_post_meta($post->ID,'_thumbnail_id',false);
  12.         $thumb = wp_get_attachment_image_src($thumb[0], 'post-thumbnail', false);
  13.         $thumb = $thumb[0];
  14. ?>
  15.  
  16.         <div class="twentyten-popular-post">
  17.             <?php if ($thumb) { ?>
  18.                 <img src="<?php echo $thumb; ?>" width=40 height=40 />
  19.             <?php } ?>
  20.             <a href="<?php echo $guid; ?>" title="<?php echo $post_title; ?>"><?php echo $post_title; ?></a>
  21.         <div class="clear"></div>
  22.         </div>
  23.         <?php }
  24.     }
  25. ?>
  26. </li>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement