Theming Exchange - Getting a Product Image of Any Registered Size

From IThemes Codex
(Difference between revisions)
Jump to: navigation, search
(Created page with "Although you can use <code>it_exchange( 'product', 'featured_image' );</code> or <code>it_exchange( 'product', 'gallery' );</code> to return a product's images within a loop, ...")
 
 
Line 1: Line 1:
Although you can use <code>it_exchange( 'product', 'featured_image' );</code> or <code>it_exchange( 'product', 'gallery' );</code> to return a product's images within a loop, there is also a function you can use to return product images of all sizes.
+
Although you can use <code>it_exchange( 'product', 'featured-image' );</code> or <code>it_exchange( 'product', 'gallery' );</code> to return a product's images within a loop, there is also a function you can use to return product images of all sizes.
  
 
<pre class="brush:php;gutter:false;toolbar:false;">
 
<pre class="brush:php;gutter:false;toolbar:false;">

Latest revision as of 10:55, September 24, 2013

Although you can use it_exchange( 'product', 'featured-image' ); or it_exchange( 'product', 'gallery' ); to return a product's images within a loop, there is also a function you can use to return product images of all sizes.

it_exchange( 'product', 'get-images' );

For example, if you have a product with one image and use the get-images function this will be the output.

	Array
		123    => Array
			thumbnail       => Array
				0  => http://example.com/path-to-image/image-150x150.jpg
				1  => [integer] 150
				2  => [integer] 150
				3  => true
	        medium          => Array
				0  => http://example.com/path-to-image/image-300x181.jpg
				1  => [integer] 300
				2  => [integer] 181
				3  => true
	        large           => Array
				0  => http://example.com/path-to-image/image-1024x618.jpg
				1  => [integer] 1024
				2  => [integer] 618
				3  => true
	        full            => Array
				0  => http://example.com/path-to-image/image.jpg
				1  => [integer] 4400
				2  => [integer] 2656
				3  => false

Where 123 is the ID of the image, followed by the available sizes.

Note that the image sizes will be different depending on the images uploaded.


Retrieving a Specific Image

You can take this function one step further by adding an ID & size to retrieve a specific product image of that size.

it_exchange( 'product', 'get-images', array( 'id' => '123', 'size' => 'full' ) );

Outputs

	Array
		0  => http://example.com/path-to-image/image.jpg
		1  => [integer] 4400
		2  => [integer] 2656
		3  => false
Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox