WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Advanced Custom Field] Displaying only the FIrst Row in Repeater (3 posts)

  1. jaeeun
    Member
    Posted 1 year ago #

    Hi,

    I have multiple images in a repeater, and I'd like to show only the first image. I found this posting and tried, but I've had no luck;

    http://old.support.advancedcustomfields.com/discussion/3674/how-to-grab-only-the-first-repeater-row/p1

    This is my code;

    <div class="column-img">
    <?php if(get_field('gallery')): ?>
    <?php while(the_repeater_field('gallery')): ?>
    
    <div id="externalnav"><div class="postitem"><div class="background"></div>
    		<a href="#" class="imghover"><img src="<?php the_sub_field('image'); ?>"/> </a>
    		<?php
    
                                $first_number = get_sub_field('image');
                                $second_number = get_field('title');
                                $num1 = (int)$first_number;
                                $num2 = (int)$second_number;
                                $total = $num1 * $num2;
                                print number_format($total);
    
                            ?>
    
        </div><!--.postitem -->
    </div><!--externalnav-->
    </div><!--column-img-->
    <?php break; ?>
    </div><!--wrapper -->
    <?php endwhile; ?>
    <?php endif; ?>

    Please help!

    Thanks,

    Jaeeun

  2. jaeeun
    Member
    Posted 1 year ago #

    Additional information: I'm trying so if I click the first image that shows up a slideshow pops up.

  3. jaeeun
    Member
    Posted 1 year ago #

    I found this in ACF's website and tried it:

    "Get the first row from a repeater

    This example shows how to find the first row from a repeater and display an image found in that row."

    <?php
    
    $rows = get_field('repeater_field_name' ); // get all the rows
    $first_row = $rows[0]; // get the first row
    $first_row_image = $first_row['sub_field_name' ]; // get the sub field value 
    
    // Note
    // $first_row_image = 123 (image ID)
    
    $image = wp_get_attachment_image_src( $first_row_image, 'full' );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <img src="<?php echo $image[0]; ?>" />

    and this is my code;

    div class="column-img">
    <br>
    <?php
    
    $rows = get_field('gallery' ); // get all the rows
    $first_row = $rows[0]; // get the first row
    $first_row_image = $first_row['image' ]; // get the sub field value 
    
    // Note
    // $first_row_image = 123 (image ID)
    
    $image = wp_get_attachment_image_src( $first_row_image, 'full' );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <div id="externalnav"><div class="postitem"><div class="background"></div>
    		<a href="#" class="imghover"><img src="<?php echo $image[0]; ?>"/> </a>
    
        </div><!--.postitem -->
    </div><!--externalnav-->
    </div><!--column-img-->
    </div><!--wrapper -->

    but it still doesn't work. the images don't show up.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.