[英]get first image in wordpress repeater array
我有一個while循環,它獲取縮略圖,然后在div中為fancybox提供所有其他圖像。 我需要它,以便在單擊拇指時可以在圖像的中繼器字段中擴展第一個圖像,而不是初始縮略圖。
我試圖將圖像取出並回波,但似乎得到的是隨機圖像。
這是我的代碼,firstImage變量是我用來嘗試從Repeater字段獲取第一張圖像的地方。
這是網站鏈接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(); ?>
好的,為此嘗試一下,可能會成功,因為您的第一篇文章給您的鏈接可能是由於get_posts更改了您的代碼
$firstImage = get_field('images');
如
$imid=get_the_ID();
$firstImage = get_field('images',$imid);
希望這能解決.. :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.