September 21, 201312 yr Good afternoon Folks! I am trying to add featured image to a post page. As the images are always going to be different sizes and I don't want them to be cropped, I thought perhaps I could set a set-height. I figured I could then somehow set it so that the width was auto and would just adjust accordingly to fit the image size and keep the proportion. How do I do this? I have tried this so far:- <?php echo get_the_post_thumbnail( $post_id, array('auto',300), $attr ); ?> But this did not work. Any help would be appreciated :-)
September 21, 201312 yr can you not just add a css class like this .featured-image-class { max-height:300px; }
September 22, 201312 yr You could try and add a new featured image size to functions.php add_image_size( 'page-feature-image', 500, 175, true ); By setting it to true it will scale the image to the exact size. If you upload an image larger than this it will scale it down as much as possible then trim off the edges. and then in your theme use this where you would like to display this image <?php the_post_thumbnail( 'page-feature-image' ); ?> Just remember that if you add a new feature image size it will only be applied to new image uploads so you will have to reupload the image to test and if it works you can use this plugin to regenerate all the images. http://wordpress.org/plugins/regenerate-thumbnails/
Create an account or sign in to comment