Note that there are some explanatory texts on larger screens.

plurals
  1. POget first image in wordpress repeater array
    primarykey
    data
    text
    <p>I have a while loop that gets a thumbnail and then all a bunch of other images in a div for fancybox. I need it so that when a thumb is clicked it expands first image in the repeater field of images rather than the initial thumbnail.</p> <p>I tried to get the image out and echo it in but it seems to get a random image instead.</p> <p>Here is my code the firstImage variable is where I am using to try get the first image from the repeater field.</p> <p>Here is a link to the site <a href="http://lsmcreative.co.nz/" rel="nofollow">http://lsmcreative.co.nz/</a></p> <pre><code> &lt;?php query_posts("posts_per_page=-1"); ?&gt; &lt;?php if(have_posts()):?&gt; &lt;?php $i = 0; ?&gt; &lt;?php while(have_posts()) : the_post();?&gt; &lt;?php $image1ID = get_field('main'); $image1 = wp_get_attachment_image_src( $image1ID, 'full-size' ); $attachment1 = get_post( $image1ID ); $image1_title = $attachment1-&gt;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]; ?&gt; &lt;li class="&lt;?php foreach($categories as $category){ echo $category-&gt;category_nicename.' '; } ?&gt;"&gt; &lt;a class="grouped_elements" rel="group&lt;?php echo $i; ?&gt;" title="&lt;?php echo $image_title; ?&gt;" href="&lt;?php echo $imageobject[0] ?&gt;"&gt; &lt;img class="hover" src="&lt;?php bloginfo('template_url') ?&gt;/img/portfolio/hover.jpg" alt="LSM Design"&gt; &lt;img src="&lt;?php echo $image1[0] ?&gt;" alt="&lt;?php echo $image1_title; ?&gt;"&gt; &lt;/a&gt; &lt;div class="lb-images"&gt; &lt;?php if(get_field('images')){ ?&gt; &lt;?php while(has_sub_field('images')): ?&gt; &lt;?php $imageID = get_sub_field('image'); $image = wp_get_attachment_image_src( $imageID, 'gallery-thumb' ); $attachment = get_post( $imageID ); $image_title = $attachment-&gt;post_title; ?&gt; &lt;a class="grouped_elements" rel="group&lt;?php echo $i; ?&gt;" href="&lt;?php echo $image[0] ?&gt;" title="&lt;?php if(get_sub_field('caption')){the_sub_field('caption');}; ?&gt;"&gt;&lt;img src="&lt;?php echo $image[0] ?&gt;" alt="&lt;?php echo $image_title; ?&gt;"&gt;&lt;/a&gt; &lt;?php endwhile; ?&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;?php else: ?&gt; &lt;?php endif; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload