Support

Account

Home Forums Add-ons Flexible Content Field ACF Flexible Content – Looping two layouts (parse error?)

Helping

ACF Flexible Content – Looping two layouts (parse error?)

    • Zecele

    • November 6, 2020 at 5:01 am

    Getting to grips with ACF and it’s flexible content field.

    I have two layouts as shown below but I can’t seem to get the second part (image_block) working correctly as it keeps popping up with a (parse error) I’m probably missing something obvious but if anyone has some advice it would be very helpful.

    <?php if( have_rows('content-h') ):?>
    
        <?php while ( have_rows('content-h') ) : the_row();?>
    
        <?php if( get_row_layout() == 'text_block' ):
                $title = get_sub_field('title');
                $description = get_sub_field('description');
                $subheading = get_sub_field('subheading');
                
            ?>
    
                <div class="col-lg-6">
                    <div class="section-title">
                        <span class="text-color"><?php echo $subheading; ?></span>
                        <h2 class="mt-3 content-title"><?php echo $title; ?></h2>
                    </div>
                </div>
                <div class="col-lg-6">
                    <p><?php echo $description; ?></p>
                </div>
    
        <?php endif; ?>
    
        </div>
    
        <div class="row justify-content-center">
        
        <?php if( get_row_layout() == 'image_block' ):
                $image = get_sub_field('image');
                $title = get_sub_field('title');
                $description = get_sub_field('description');
                $link = get_sub_field('link');
                
                ?>
    
                <div class="col-lg-3 col-md-6 col-12">
                    <div class="intro-item mb-5 mb-lg-0"> 
                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" alt="" class="img-fluid w-100">
                        <h4 class="mt-4 mb-3"><?php echo $title; ?></h4>
                        <p><?php echo $description; ?></p>
                    </div>
                </div>
    
        <?php endwhile; ?>
    <?php endif; ?>
    
  • You are missing an endif for ‘ if( get_row_layout() == ‘image_block’ ):`

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.