我有一个网页,使用ACF Repeater字段从wordpress调用7张图像。
我想要做的是获取图像的URL列表,然后将它们随机播放,以便它们的图像随机出现在网页上。当我使用($image['url'])
调用图像时,显示的唯一图像是上传到wordpress网站的最后一张图像。
<?php
// Call the ACF Gallery images
$imageArray = get_field('company_logos', 13);
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $imageArray ):
while( have_rows('company_logos', 13) ) : the_row();
$image = get_sub_field('image');
// $content = get_sub_field('content');
//shuffle ($image['url']);
$arr = $image['url'];
shuffle($arr);
print_r($arr);
endwhile;
endif; ?>
当我将图像URL回显到屏幕时,它们的格式为:
http://localhost/wordpress/wp-content/uploads/2016/07/a.jpg
http://localhost/wordpress/wp-content/uploads/2016/07/b.png
http://localhost/wordpress/wp-content/uploads/2016/07/c.jpg
http://localhost/wordpress/wp-content/uploads/2016/07/d.jpg
http://localhost/wordpress/wp-content/uploads/2016/07/e.jpg
http://localhost/wordpress/wp-content/uploads/2016/07/f.jpg
http://localhost/wordpress/wp-content/uploads/2016/07/g.jpg
任何人都知道如何做到这一点? 谢谢!
答案 0 :(得分:0)
您是否从$ image [&#39; url&#39;]获取了图片列表?它首先返回一个数组吗?如果确实如此,则您的解决方案应该有效如果它不是数组,而是由逗号分隔的URL字符串,请在第2个语句之前执行以下操作。所以,新代码如下所示,
$urls = $image['url'];
$arr = explode(" ", $urls);
shuffle($arr);
print_r($arr);