2016-07-24 21 views
-2

我有一个网页,使用ACF中继器字段调用来自wordpress的7个图像。如何使用ACF在PHP中随机化URL列表?

我想要做的是获取图像的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 

任何人都知道如何做到这一点? 谢谢!

+1

请澄清您的具体问题或添加其他详细信息以突出显示您需要的内容。正如目前所写,很难确切地说出你在问什么。请参阅[如何提问](http://stackoverflow.com/help/how-to-ask)页面以获得澄清此问题的帮助。 –

+0

第一篇文章的道歉,这是否更有意义? – HowsThatMonkey

回答

0

你是否从$ image ['url']获取图片列表?它是否首先返回一个数组?如果这样做,那么你的解决方案应该工作如果它不是数组,而是用逗号分隔的一串URL,请在第二条语句之前执行以下操作。因此,新代码将如下所示:

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

第一篇文章的道歉,这是否更有意义?我厌倦了你的解决方案,但它没有奏效。 – HowsThatMonkey