0

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 ?

2

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

2

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.

1

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.

-2
<?php
// 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 )
    break;

$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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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