如何使用 ACF 随机化 PHP 中 URL 的列表?

How to randomise a list of URL's in PHP using ACF?

我有一个网页使用 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

有人知道怎么做吗? 谢谢!

你从 $image['url'] 得到图像列表了吗?它 return 首先是一个数组吗?如果确实如此,那么您的解决方案应该有效。如果它不是数组而是一串用逗号分隔的 URL,则在第二条语句之前执行以下操作。因此,新代码如下所示,

$urls = $image['url'];
$arr = explode(" ", $urls);
shuffle($arr);
print_r($arr);