I've been trying to read up on this in the manual, but basically I've got an array
where I'm trying to reverse it and exclude the last item. So I got 14 items currently in my array and I'm getting it to reverse and it shows 14-2. My code got it to exclude the last item. So I guess it technically works, but I actually want it to output as 13-1. I tried using array_pop
and array_shift
but I didn't know how to integrate it with array_reverse
.
function smile_gallery( $atts ) {
if( have_rows('smile_gallery', 3045) ):
$i = 1;
$html_out = '';
$html_out .= '<div class="smile-container">';
$html_out .= '<div class="fg-row row">';
// vars
$rows = get_field('smile_gallery', 3045);
$count = count( get_field('smile_gallery', 3045) );
$html_out .= '<div class="col-md-8">'; // col-md-offset-1
$html_out .= '<div class="smile-thumbs">';
foreach( array_reverse($rows) as $row) :
// vars
$week = "smile_week";
$img = "smile_img";
$caption = "smile_caption";
// Do stuff with each post here
if( $i < $count) :
$html_out .= '<div class="smile-thumb-container">';
$html_out .= '><h6>Week ' . $row["smile_week"] . '</h6></a>'; // smile thumb week
$html_out .= '</div>'; // smile thumb container
endif;
$i++;
endforeach;
$html_out .= '</div>';
$html_out .= '</div>';
$html_out .= '</div>';
$html_out .= '</div>'; // smile container
endif;
return $html_out;
}
add_shortcode( 'show_smiles', 'smile_gallery' );