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?

Read More

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 )

Related posts

Leave a Reply

5 comments

  1. 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).'">';
    }
    
  2. 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….

  3. <?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

  4. Use this code.

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