Home Forums General Issues How do you get the last row of a repeater? Reply To: How do you get the last row of a repeater?

  • I fixed the issue, but I want to do something additional in this function. I want to be able to also loop through all the rows and output all except the last one. I have two columns. The left will output the last row and the right will output all but the last.

    function smile_gallery( $atts ) {
        if( have_rows('smile_gallery', 3045) ):
        $i = 0;
        $html_out = '';
        $html_out .= '<div class="smile-container">';
            $rows = get_field('smile_gallery', 3045);
            $end_row = end($rows);
            $recent = $end_row['smile_week'];
            $html_out .= '<div class="col-md-6">';
                $html_out .= '<div class="smile-recent">';
                    $html_out .= $recent;
                $html_out .= '</div>';
            $html_out .= '</div>';
            $html_out .= '<div class="col-md-6">';
                $html_out .= '<div class="smile-thumbs">';
                while( have_rows('smile_gallery', 3045) ): the_row();
                $week = get_sub_field('smile_week', 3045);
                $img = get_sub_field('smile_img', 3045);
                // Do stuff with each post here
                $html_out .= '<div class="smile-img">';
                    $html_out .= $week;    
                $html_out .= '</div>';
                $html_out .= '</div>';
            $html_out .= '</div>';
        $html_out .= '</div>'; // smile container
        return $html_out;
    add_shortcode( 'show_smiles', 'smile_gallery' );

    This is the full function. To take it an even step further, it would be cool to order the rows by $week. $week outputs a number.