Now i tried some other ways….
<?php /* Start popular Post */ ?>
<li>
<h3>Popular Posts</h3>
<ul class="bullets">
<?php
$args = array( 'numberposts' => 5 );
$thumbnails = get_posts($args);
foreach ($thumbnails as $thumbnail) {
if ( has_post_thumbnail($thumbnail->ID)) {
echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
echo '</a>';
}
}
?>
</ul>
</li>
<?php /* End popular Post */ ?>
and its working but its only showing the most recent posts. unless most popular post 🙁
…..
having trouble with popular post…
<?php /* Start popular Post */ ?>
<li>
<h3>Popular Posts</h3>
<ul class="bullets">
<?php
$popular_posts = $wpdb->get_results("SELECT id,post_title FROM {$wpdb->prefix}posts ORDER BY comment_count DESC LIMIT 0,3");
foreach($popular_posts as $pop) {
if ( has_post_thumbnail($pop->ID) ) {
?>
<li>
<?php the_post_thumbnail(array(100,100)); ?>
</li>
<?php
}
}
?>
</ul>
</li>
<?php /* End popular Post */ ?>
i am trying to grab 3 popular posts but when i am using the above code they are just showing me image of my recent post …
help me to figure out this
Try using
get_the_post_thumbnail( $id, $size, $attr )and pass in the Post ID. Also note that you should specify in your querypost_type = 'post'to filter out non-posts.Documentation: http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
—
I’ve confirmed locally that the following works: