Support

Account

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; ?>