2013-03-20 11 views
0

我有一個while循環獲取一個縮略圖,然後是一個div中的所有其他圖像的一堆fancybox。我需要它,這樣當點擊一個拇指時,它會擴展圖像的中繼器域中的第一個圖像,而不是最初的縮略圖。在wordpress中繼器陣列中獲得第一個圖像

我試圖讓圖像出來,並回聲它,但它似乎得到一個隨機圖像。

這是我的代碼firstImage變量是我用來嘗試從中繼器字段獲取第一個圖像。

下面是該網站的鏈接http://lsmcreative.co.nz/

<?php query_posts("posts_per_page=-1"); ?> 
    <?php if(have_posts()):?> 
    <?php $i = 0; ?> 
    <?php while(have_posts()) : the_post();?> 

     <?php 
     $image1ID = get_field('main'); 
     $image1 = wp_get_attachment_image_src($image1ID, 'full-size'); 
     $attachment1 = get_post($image1ID); 
     $image1_title = $attachment1->post_title; 

     $categories = get_the_category(); 
     $i++; 

     $firstImage = get_field('images'); 
     $firstImageId = $firstImage[0]['image' ]['id' ]; 
     $imageobject = wp_get_attachment_image_src($firstImageId, 'full-size' ); // returns an array 
     $image_url = $imageobject[0];   
     ?>       

      <li class="<?php foreach($categories as $category){ echo $category->category_nicename.' '; } ?>"> 

       <a class="grouped_elements" rel="group<?php echo $i; ?>" title="<?php echo $image_title; ?>" href="<?php echo $imageobject[0] ?>"> 
        <img class="hover" src="<?php bloginfo('template_url') ?>/img/portfolio/hover.jpg" alt="LSM Design"> 
        <img src="<?php echo $image1[0] ?>" alt="<?php echo $image1_title; ?>"> 
       </a> 

       <div class="lb-images"> 

        <?php if(get_field('images')){ ?> 
         <?php while(has_sub_field('images')): ?> 
          <?php 
          $imageID = get_sub_field('image'); 
          $image = wp_get_attachment_image_src($imageID, 'gallery-thumb'); 
          $attachment = get_post($imageID); 
          $image_title = $attachment->post_title; 
         ?> 
         <a class="grouped_elements" rel="group<?php echo $i; ?>" href="<?php echo $image[0] ?>" title="<?php if(get_sub_field('caption')){the_sub_field('caption');}; ?>"><img src="<?php echo $image[0] ?>" alt="<?php echo $image_title; ?>"></a> 
         <?php endwhile; ?> 
        <?php } ?> 

       </div> 

      </li> 

    <?php endwhile; ?> 
    <?php else: ?> 
    <?php endif; ?> 
    <?php wp_reset_query(); ?> 
+0

你能解釋哪一個是你的中繼器字段和圖像什麼出你把使用,網址,對象或圖像編號 – anstrangel0ver 2013-03-20 07:36:47

+0

我的中繼器字段被稱爲圖像,我想獲得子字段圖像。但我試圖獲取該字段中的第一個圖像的src,並將其用於在lb圖像中的if和while循環之前的標籤的src – 2013-03-20 08:00:19

+0

其工作正常,我從變量$獲得第一個圖像url IMAGE_URL。 while echo $ image_url你得到了什麼值? – anstrangel0ver 2013-03-20 08:20:52

回答

0

確定給一試的,這可能是因爲您的樅樹後是給你的鏈接可能會因工作get_posts 改變我們的代碼

$firstImage = get_field('images'); 

由於

$imid=get_the_ID(); 
$firstImage = get_field('images',$imid); 

希望這將工作了.. :)

+0

我想我看到你在那裏試圖做什麼,但它沒有工作:( – 2013-03-20 10:01:40

+0

你可以嗎的print_r($ firstImage);和後whas其上部分返回其中烏爾不歌廳圖像 – anstrangel0ver 2013-03-20 10:04:31

+0

陣列 ( [0] =>數組 ( [圖像] => 80 ) ) – 2013-03-20 19:39:27