Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images)));
    echo "<img src=\"{$firstImageSrc[0]}\" width=\"32\" height=\"32\" />"; ?>

    Stick the above code in the loop and that should do it. It grabs the first key from the $images array and then uses that to get the necessary url from wp_get_attachment_src().

    Note that this code only resizes the image using HTML, it doesn’t do anything to the thumbnail file itself. You’d need to change the size settings for thumbnails in /wp-admin/options-misc.php to change the image file dimensions, although that won’t change the size of existing thumbnails on your site, you’d need to fix those up manually if you want them changing.

    wp_get_attachment_image() and wp_get_attachment_image_src() in /wp-includes/media.php seems to do what you want (in WordPress 2.6.1, at least). Running the following code inside the loop will generate thumbnails of all images associated with the current post:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    foreach( $images as $imageID => $imagePost )
    	echo wp_get_attachment_image($imageID, 'thumbnail', false);

    You can use the array returned by wp_get_attachment_image_src() to create links instead of image tags, or check that the thumbnails are the correct size.

    BTW, the ‘post_parent’ argument needs passing to get_children() or you end up with an array of all the images in your database…

Viewing 2 replies - 1 through 2 (of 2 total)