I'm using the following code to pull the featured image from a post category. I have repeated this code another 3 times in my template to add different categories. I would like all the images to be the same size, but are all different sizes.
I've tried to create a new custom image thumbnail size (preview-thumb) in functions.php
add_theme_support( 'post-thumbnails' ); // this enable thumbnails
add_image_size( 'preview-thumb', 300, 185, true ); //this sets your default size
And then I'm using this code to fetch the thumbnail:
<!-- WILDLIFE SECTION -->
<?php $custom_query = new WP_Query(array ('cat' => 34, 'showposts' => 1));
query_posts($custom_query);
while($custom_query->have_posts()) : $custom_query->the_post();?>
<div class="span3">
<div class="myimage">
<a href="<?php the_permalink() ?>" rel="bookmark">
<!-- Check for post thumbnail & display it. Note - this will be the featured image of your post -->
<?php
if ( has_post_thumbnail())
{
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'preview-thumb' );
echo '<img src="' . $thumb[0] . '">';
} else {
echo 'No post thumbnail.';
}
?>
</a>
</div>
I could get around this by setting a fixed or min width, but want to avoid this if possible. Don't understand why the images are all different sizes. I've tried regenerating all thumbnails with a plugin, but that didn't help.