2013-12-15 14 views
-1

你好,我正在試圖創建在我的WordPress的燈箱畫廊,我設法讓大部分的代碼適用於從圖庫中抓取圖像。但是我不知道如何讓自己的網址爲他們的原始文件....WordPress的PHP獲取圖像gallerys的URL?我得到了一部分代碼工作

PHP

<?php $post_content = get_the_content(); 
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); 
    $array_id = explode(",", $ids[1]); 
    $item = 0; 
    while ($array_id[$item] != ''){ 
     if($item == 0){ 
      echo wp_get_attachment_image($array_id[$item], 'medium'); 
     }else{ 
        echo "<a ref='".wp_get_attachment_image($array_id[$item])."'>";}       
     $item++; 
     } 
?> 

所以我的想法是,以顯示在畫廊的第一圖像,我有完成的IMG第一個ECHO,而不是所有其他圖像,我只想要鏈接到原始文件。

我最後的代碼需要看起來像這樣:

<a rel="group1" href="image_big_1.jpg"><img src="image_small_1.jpg" alt=""/></a> 
<a rel="group1" href="image_big_3.jpg"></a> 
<a rel="group1" href="image_big_4.jpg"></a> 
<a rel="group1" href="image_big_5.jpg"></a> 
<a rel="group1" href="image_big_6.jpg"></a> 

而且你會建議爲相對=「」我需要這是與畫廊每一個崗位,我不知道該用什麼我只能不會使用TITLE,因爲如果他們輸入的標題相同,則會出現問題。我猜可能是由current_time定義的某種(RANDOM)前綴?

請幫 謝謝

回答

0

我找到了解決辦法和編輯我的代碼工作:

這是代碼來完成上述:使用

<?php $post_content = get_the_content(); 
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); 
    $array_id = explode(",", $ids[1]); 
    $item = 0; 
    while ($array_id[$item] != ''){ 
     $url = wp_get_attachment_image_src($array_id[$item]); 
      if($item == 0){ 
       echo "<a href='".$url[0]."'>".wp_get_attachment_image($array_id[$item], 'gallery-thumb')."</a>"; 
      }else{ 
       echo "<a href='".$url[0]."'</a>";}      
     $item++; 
     } 
?> 

參考:http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

謝謝大家!