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.' …';
} else { echo ''.$title2.''; }
echo '</a>'; echo'{';
echo ''.$commentcount.''; echo'}'; echo ' </p>';
echo '</li>';
echo '</div>';
} } ;
It does not display anything. Any ideas? Your help is greatly appreciated.