我有一個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(); ?>
你能解釋哪一個是你的中繼器字段和圖像什麼出你把使用,網址,對象或圖像編號 – anstrangel0ver 2013-03-20 07:36:47
我的中繼器字段被稱爲圖像,我想獲得子字段圖像。但我試圖獲取該字段中的第一個圖像的src,並將其用於在lb圖像中的if和while循環之前的標籤的src – 2013-03-20 08:00:19
其工作正常,我從變量$獲得第一個圖像url IMAGE_URL。 while echo $ image_url你得到了什麼值? – anstrangel0ver 2013-03-20 08:20:52