Home › Forums › Add-ons › Flexible Content Field › using a layout twice › Reply To: using a layout twice
So playing around I was able to sort of trick it… I check to see if any layouts are left even if have rows is now false.
$id = get_the_ID();
$sections = get_field( 'sections'); //get the section names
$sections_count = count($sections); //count them
if( have_rows('sections', $id) ):
//check if have row OR THERE ARE STILL LAYOUTS LEFT
while( have_rows('sections', $id) || $sections_count ): the_row();
$section = get_row_layout();
//lower amount of layouts left
$sections_count--;
//each layout has its own file. very clean output. It's how I do.
if( file_exists( locate_template( 'template-parts/blocks/' . $section . '.php') )) {
include( locate_template( 'template-parts/blocks/' . $section . '.php' ) );
}
endwhile;
endif;
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.