我正在尝试对while
中的行进行排序,以便它们是3,2,1而不是1,2,3。如果它可以按$week
排序,因为它返回一个数值,它将是dope。我阅读了关于排序行的ACF页面,但鉴于我已经在这里有一些自定义代码来排除while
中的最后一行我不知道如何合并它们。
function smile_gallery( $atts ) {
if( have_rows('smile_gallery', 3045) ):
$i = 1;
$html_out = '';
$html_out .= '<div class="smile-container">';
// vars
$rows = get_field('smile_gallery', 3045);
$end_row = end($rows);
$recent = $end_row['smile_week'];
$count = count( get_field('smile_gallery', 3045) );
$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();
// vars
$week = get_sub_field('smile_week', 3045);
$img = get_sub_field('smile_img', 3045);
$caption = get_sub_field('smile_caption', 3045);
// Do stuff with each post here
if( $i < $count) :
// vars
$order = array();
$html_out .= '<div class="smile-thumb-container">';
$html_out .= '<div class="smile-thumb-img" style="background: url('. $img .') no-repeat center top; background-size: cover;">';
$html_out .= '</div>'; // smile thumb img
$html_out .= '<a class="smile-thumb-week" href="' . $img . '" data-lightbox="smile-set" ';
if ($caption) :
$html_out .= 'data-title="' . 'Week ' . $week . ' - ' . $caption . '"';
endif;
$html_out .= '><h6>Week ' . $week . '</h6></a>'; // smile thumb week
$html_out .= '</div>'; // smile thumb container
endif;
$i++;
endwhile;
$html_out .= '</div>';
$html_out .= '</div>';
$html_out .= '</div>'; // smile container
endif;
return $html_out;
}
add_shortcode( 'show_smiles', 'smile_gallery' );