WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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




(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)

        // 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
up vote 2 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:



Or here there is good info too:

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

share|improve this answer

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

You should try using it like this:

    // 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
// code copied from adjacent_image_link() in wp-include/media.php
$attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ));
foreach ( $attachments as $k => $attachment )
  if ( $attachment->ID == $post->ID )

$next_url =  isset($attachments[$k+1]) ? get_permalink($attachments[$k+1]->ID) : get_permalink($attachments[0]->ID);
$prev_url =  isset($attachments[$k-1]) ? get_permalink($attachments[$k-1]->ID) : get_permalink($attachments[0]->ID);

sample : images

share|improve this answer

Your Answer


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.