invp_get_the_photos( array $sizes,  $post_ID = null )

invp_get_the_photos


Description Description

Fill arrays of thumb and large <img> elements and URLs to simplify the use of of vehicle photos.


Top ↑

Parameters Parameters

$sizes

(array) (Required)


Top ↑

Return Return

(array) An array of thumbnail and full size HTML <img> elements plus URLs


Top ↑

Source Source

File: includes/template-tags.php

function invp_get_the_photos( $sizes, $post_ID = null )
{
	/**
	 * Backwards compatibility to versions before 5.4.0 where the
	 * incoming argument was a string not an array.
	 */
	if( ! is_array( $sizes ) )
	{
		$sizes = array( $sizes );
	}

	if( empty( $post_ID ) )
	{
		$post_ID = get_the_ID();
	}

	$image_args = array(
		'meta_key'       => apply_filters( 'invp_prefix_meta_key', 'photo_number' ),
		'posts_per_page' => -1,
		'order'          => 'ASC',
		'orderby'        => 'meta_value_num',
		'post_mime_type' => 'image',
		'post_parent'    => $post_ID,
		'post_status'    => 'inherit',
		'post_type'      => 'attachment',
	);

	$images = get_posts( $image_args );

	$image_urls = array();
	foreach( $images as $image )
	{
		foreach( $sizes as $size )
		{
			$img_element = wp_get_attachment_image(
				$image->ID,
				$size,
				false,
				array( 'class' => "attachment-$size size-$size invp-image" )
			);

			$image_urls[$size][] = $img_element;

			if( 'large' == $size )
			{
				$image_urls['urls'][] = INVP::extract_image_element_src( $img_element );
			}
		}
	}

	/**
	 * Backwards compatibility to versions before 5.4.0 where the
	 * incoming argument was a string not an array.
	 */
	if( 1 == sizeof( $sizes ) )
	{
		return $image_urls[$sizes[0]];
	}

	return $image_urls;		
}