2016-07-24 25 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