Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm confused, because there are a lots of functions about attachments . I've tried a lots of functions. I'm setting a featured image for my every blog post.

I have to get different sizes of this image. FOr example a need this variations of featured image

600px*400px

300px*150px

64px*64px

(Images can be cropped).

I'm adding these new image sizes (in functions.php):

add_image_size('custombig', 600, 400, TRUE);
add_image_size('customsmall', 300, 152, TRUE);
add_image_size('customimage', 64, 64, TRUE);

(in single.php)

 <?php
        // inside a Loop
        if (has_post_thumbnail( $post->ID ))
            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'customsmall' );
    ?>
    <img alt="" src="<?php echo $image[0]; ?>" />

But it's printing full size of image. Not cropping or resizing it.

Can you teach me getting different sizes of attached images, or suggest me a few articles about this ?

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Since you have defined the featured image for each post with using

<?php the_post_thumbnail( 'custombig' ); // or another custom size name ?>

should be enough, for info you can read:

http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature

http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

Or here there is good info too:

How wordpress handle upload images and how to use them in the code

share|improve this answer
add comment

Is it possible that you defined these custom image sizes after the images in question were already uploaded? If so, you'll need to re-generate the thumbnails for these images, since WP doesn't automatically retroactively create new image sizes.

I personally use Regenerate Thumbnails for this. It's great.

share|improve this answer
add comment

You should try using it like this:

<?php
    // inside a Loop
    if (has_post_thumbnail( $post->ID ))
        $imageBig = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array(600, 400) );
        $imageMid = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array(300, 152) );
        $imageSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array(64, 64) );
?>
<img alt="" src="<?php echo $imageBig; ?>" />
<img alt="" src="<?php echo $imageMid; ?>" />
<img alt="" src="<?php echo $imageSmall; ?>" />

.
Hope This helps :)
Cheers, Sagive.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.