Bigtech Ideas
Bigtech Ideas

Reputation: 105

How to display an array of multiple images?

I am using this wordpress plugin to upload multiple images. http://wordpress.org/plugins/upload-multiple-image/

It gives me a function that return an array get_multiple_image($post_id). But next I don't know how to display this array?

I want to display all images in this format.

What I should do to get images path in $img1, $img2, $img3, $img4.

<img src="<?php echo $img1; ?>" alt="">
<img src="<?php echo $img2; ?>" alt="">
<img src="<?php echo $img3; ?>" alt="">
<img src="<?php echo $img4; ?>" alt="">

if I do this print_r(get_multiple_image($post_id)); it return this

Array ( [0] => http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png [1] => http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png [2] => http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png [3] => http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png )

Upvotes: 1

Views: 11310

Answers (5)

dialogik
dialogik

Reputation: 9552

Quick and easy:

// Get images as array
$images = get_multiple_image($post_id);

// Loop over images and echo
foreach($images as $img) {
    echo '<img src="'.$img.'" alt="">';
}

Or if you want to set an alternative image text derived from the loop index:

// Loop over images and echo
for($i = 0; $i < count($images); $i++) {
    echo '<img src="'.$images[$i].'" alt="Image #'.($i+1).'">';
}

Upvotes: 1

user1865618
user1865618

Reputation:

Use this code.

$post_id = get_the_ID();
$MultiImages = get_multiple_image($post_id);

foreach($MultiImages as $img)
{
  echo "<img src='".$img."' alt=''>";
} 

Upvotes: 0

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

<?php
$images=array('http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png','http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png','http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png','http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png');

print_r($images);
foreach($images as $key){
echo "<img src='".$key."' alt=''>";
}

The output will be,

Array
(
    [0] => http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png
    [1] => http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png
    [2] => http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png
    [3] => http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png
) // your array

and the result

<img src='http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png' alt=''>

See example

Upvotes: 0

Vishal Sharma
Vishal Sharma

Reputation: 1372

Try this

$AllImages = get_multiple_image($post_id);

foreach($AllImages as $image)
{
  echo "<img src='".$image."' alt=''>";
} 

Upvotes: 0

Rakesh Sharma
Rakesh Sharma

Reputation: 13738

try

$images = get_multiple_image($post_id);
foreach($images as $img) {?>
<img src="<?php echo $img; ?>" alt="">
<?php }?>

or for path you can use array index values

$img1 = $images[0];
$img2 = $images[1];

and so on....

Upvotes: 1

Related Questions