Home › Forums › Add-ons › Flexible Content Field › Reusing flex layout multiple times on one page › Reply To: Reusing flex layout multiple times on one page
<?php
/*
Template Name: Coaching (Flex Layout)
*/
get_header();
?>
<?php
if( have_rows('coaching_flex_sections') ):
// not needed
//$sections = get_field( 'coaching_flex_sections' );
?>
<div class="coaching flex-sections">
<?php
while( have_rows('coaching_flex_sections') ): the_row();
// while( have_posts() ): the_post();
// Loop through flexible fields and load the respective file for each.
// double loop over rows -- remove
// foreach( $sections as $i => $section ) {
// change to get_row_layout()
$part = get_stylesheet_directory().'/_template-parts/flex-layout/sections/'.get_row_layout().'.php';
if ( file_exists( $part ) ) {
include( $part );
} else {
echo '<!-- Error: No such flexible field type "'. esc_html($section['acf_fc_layout']) .' at '. esc_html($part) .'" -->';
}
// } // end of nested double loop - remove
// endwhile;
endwhile;
?>
</div>
<?php 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.