I use this code to display Most popular posts based on view count, but I dont have images in post content I have all images attached to post via attachment (gallery)
How to replace this "thimthumb" thumbnail with first attachment of this listed posts?
<div id="popular" class="widgets">
<?php _e('<h2>Popular</h2>','iphoto');?>
<ul>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'paged' => $paged,
'order' => DESC,
'showposts' => 9
);
query_posts($args);
while (have_posts()) : the_post();
$output = preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $imgs);
$cnt = count($imgs);
?>
<li>
<?php if ( $cnt > 0 ) { ?>
<a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo '<img src="'.get_bloginfo('template_url').'/timthumb.php?src='.$imgs[1].'&w=60&h=60&zc=1" />';?></a>
<?php } else { ?>
<a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img alt="<?php the_title(); ?>" src="<?php bloginfo('template_url'); ?>/timthumb.php?src=<?php bloginfo('template_url'); ?>/images/default.jpg&w=60&h=60&zc=1" /></a>
<?php } ?>
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
<div class="clear"></div>