Support

Account

Home Forums Add-ons Flexible Content Field ACF Blocks with Flexible Content conflicting

Solving

ACF Blocks with Flexible Content conflicting

  • Hi everyone,

    I have created ACF Flexible content with different layouts (type block). Each layout has it own php template that is called with following:

    <?php if ( have_rows( 'sections' ) ) : ?>
    <?php while ( have_rows('sections' ) ) : the_row();
    if ( get_row_layout() == 'hero' ) :
    get_template_part('template-parts/sections/section', 'hero');
    elseif ( get_row_layout() == 'home_references' ) :
    get_template_part('template-parts/sections/section', 'home_references');
    elseif ( get_row_layout() == 'news_articles' ) :
    get_template_part('template-parts/sections/section', 'news_articles');
    <?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Now the problems is: When I add this layouts in Front “home” Page, only one get displayed. Depending on its position in the page (See the attached image). If I changed the positions the one always in bottom get displayed and other one is not visible.
    Anyone has had this issue before ? what am I doing wrong ?! this is driving me crazy

  • Is this your exact code? If it is then you have an extra opening php tag that appears before your first endif. There is no closing php tag on the code that precedes this. I’m not sure if this would cause it, but it would cause something to go wrong.

  • No this my full code i m using

    
    <?php if ( have_rows( 'sections' ) ) : ?>
        <?php while ( have_rows('sections' ) ) : the_row();
            if ( get_row_layout() == 'hero' ) :
                get_template_part('template-parts/sections/section', 'hero');
    
            elseif ( get_row_layout() == 'platforms' ) :
                get_template_part('template-parts/sections/section', 'platforms');
    
            elseif ( get_row_layout() == 'aboutus' ) :
                get_template_part('template-parts/sections/section', 'aboutus');
    
            elseif ( get_row_layout() == 'centralized_content' ) :
                get_template_part('template-parts/sections/section', 'centralized_content');
    
            elseif ( get_row_layout() == 'featured_services' ) :
                get_template_part('template-parts/sections/section', 'featured_services');
    
            elseif ( get_row_layout() == 'featured_content' ) :
                get_template_part('template-parts/sections/section', 'featured_content');
    
            elseif ( get_row_layout() == 'carousel_clients' ) :
                get_template_part('template-parts/sections/section', 'carousel_clients');
    
            elseif ( get_row_layout() == 'short_parallax' ) :
                get_template_part('template-parts/sections/section', 'short_parallax');
    
            elseif ( get_row_layout() == 'customers' ) :
                get_template_part('template-parts/sections/section', 'customers');
    
            elseif ( get_row_layout() == 'references' ) :
                get_template_part('template-parts/sections/section', 'references');
    
            elseif ( get_row_layout() == 'all_references' ) :
                get_template_part('template-parts/sections/section', 'all_references');
    
            elseif ( get_row_layout() == 'video_columns' ) :
                get_template_part('template-parts/sections/section', 'video_columns');
    
            elseif ( get_row_layout() == 'two_columns' ) :
                get_template_part('template-parts/sections/section', 'two_columns');
    
            elseif ( get_row_layout() == 'one_column' ) :
                get_template_part('template-parts/sections/section', 'one_column');
    
            elseif ( get_row_layout() == 'faq_contents' ) :
                get_template_part('template-parts/sections/section', 'faq_contents');
    
            elseif ( get_row_layout() == 'team_members' ) :
                get_template_part('template-parts/sections/section', 'team_members');
    
            elseif ( get_row_layout() == 'latest_articles' ) :
                get_template_part('template-parts/sections/section', 'latest_articles');
    
            elseif ( get_row_layout() == 'blog_list' ) :
                get_template_part('template-parts/sections/section', 'blog_list');
    
            elseif ( get_row_layout() == 'contactbox' ) :
                get_template_part('template-parts/sections/section', 'contactbox');
    
            elseif ( get_row_layout() == 'contact_details' ) :
                get_template_part('template-parts/sections/section', 'contact_details');
    
            elseif ( get_row_layout() == 'office_location' ) :
                get_template_part('template-parts/sections/section', 'office_location');
    
            elseif ( get_row_layout() == 'contactus_team' ) :
                get_template_part('template-parts/sections/section', 'contactus_team');
    
            elseif ( get_row_layout() == 'seo' ) :
                get_template_part('template-parts/sections/section', 'seo');
                ?>
            <?php endif; ?>
        <?php endwhile; ?>
    <?php endif; ?>
    
  • I’m don’t see why you would be having the issue you’re having, but I will suggest a way to optimize your code that could help make it easier to work with.

    
    if (have_rows('sections')) {
      while (have_rows('sections')) {
        the_row();
        get_template_part('template-parts/sections/section', get_row_layout());
      }
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.