WordPress.org

Ready to get started?Download WordPress

Forums

Widget problem for popular posts with thumbnails (2 posts)

  1. revolutionfrance
    Member
    Posted 4 years ago #

    Hello, I am trying to make a new widget that will display popular posts (by comments) with a thumbnails, but it is not working. I have searched the forums but to no avail. Here is the code:

    $result = $wpdb->get_results("SELECT comment_count,id,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
    				foreach ($result as $post) {
    				setup_postdata($post);
    				$postid = $post->id;
    				$title2 = $post->post_title;
    				$commentcount = $post->comment_count;
    				$titlelim = substr($title2,0,30);
    				if ($commentcount != 0) { 
    
    				echo '<div class="poppostcom">';
    				echo '<li>';
    
    				$image = get_post_meta($post->id, 'bigphoto', true); /* Replace lead_image with the name of the custom field for the image you want to use */
    				echo '<div class="popimgs">';
    				echo '<img alt="" src="http://localhost/wordpress/wp-content/themes/norwegiangrunge/timthumb/timthumb.php?src='.$image.'&h=30&w=30&zc=1" />';
    				echo '</div>';
    				echo '<p><a href="'.get_permalink('.$postid.').'" title="'.$title.'">';
    				if (strlen($title2) > 50 ) { echo ''.$titlelim.' &hellip;';
    				 } else { echo ''.$title2.''; }
    
    				echo '</a>'; echo'{';
    				echo ''.$commentcount.''; echo'}'; echo '&nbsp; </p>';						
    
    				echo '</li>';
    				echo '</div>';
    
    				 } } ;

    It does not display anything. Any ideas? Your help is greatly appreciated.

  2. revolutionfrance
    Member
    Posted 4 years ago #

    Any ideas? It seems that the problem is with this line:

    $result = $wpdb->get_results("SELECT comment_count,id,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
    				foreach ($result as $post) {

Topic Closed

This topic has been closed to new replies.

About this Topic