Forums

Is there a tag for the different image sizes? (4 posts)

  1. Pete
    Member
    Posted 3 years ago #

    Is there a tag for the medium and thumbnail images of the original full size uploaded image?

    You know how WP creates 2 new images of different sizes than the full size image that is uploaded...
    1. image.jpg
    2. image-300x300.jpg (medium) - this is a newly created image
    3. image-150x150.jpg (thumbnail) - this is a newly created image

    the dimensions may change, so i was wondering if there is a tag that will display the 'medium' or the 'thumbnail' version of each image

  2. Otto
    Tech Ninja
    Posted 3 years ago #

    What exactly do you mean by "tag"?

    The wp_get_attachment_image() function can get any attachment image by ID, if you know the attachment ID. It takes a second parameter of "medium", "thumbnail", "full", "large", etc.

  3. Pete
    Member
    Posted 3 years ago #

    that could be it... i want to get/display the thumbnail version of the "image.jpg" i have uploaded

  4. noelgreen
    Member
    Posted 3 years ago #

    So what am I doing wrong to get the medium image to display?

    function postimagebg($size=medium) {
    	if ( $images = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image')))
    	{
    		foreach( $images as $image ) {
    			$attachmenturl=wp_get_attachment_thumb_url($image->ID, medium );
    			$attachmentimage=wp_get_attachment_image( $image->ID, $size );
    
    			echo ''.$attachmenturl.'';
    		}
    	} else {
    		bloginfo('template_url');
    		echo '/images/no_image.jpg';
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic