我正在使用这个wordpress插件上传多个图片。 http://wordpress.org/plugins/upload-multiple-image/
它为我提供了一个返回数组get_multiple_image($post_id)
的函数。但接下来我不知道如何显示这个数组?
我想以这种格式显示所有图像。
我应该如何在$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="">
如果我执行此操作print_r(get_multiple_image($post_id));
,则返回此
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 )
答案 0 :(得分:1)
试
$images = get_multiple_image($post_id);
foreach($images as $img) {?>
<img src="<?php echo $img; ?>" alt="">
<?php }?>
或路径可以使用数组索引值
$img1 = $images[0];
$img2 = $images[1];
依旧......
答案 1 :(得分:0)
试试这个
$AllImages = get_multiple_image($post_id);
foreach($AllImages as $image)
{
echo "<img src='".$image."' alt=''>";
}
答案 2 :(得分:0)
<?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=''>";
}
输出将是,
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
和结果
<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=''>
答案 3 :(得分:0)
使用此代码。
$post_id = get_the_ID();
$MultiImages = get_multiple_image($post_id);
foreach($MultiImages as $img)
{
echo "<img src='".$img."' alt=''>";
}