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);
$i++;
// Do stuff with each post here
$html_out .= '<div class="smile-img">';
$html_out .= $week;
$html_out .= '</div>';
endwhile;
$html_out .= '</div>';
$html_out .= '</div>';
$html_out .= '</div>'; // smile container
endif;
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.