ACF 灵活内容 - 循环两种布局(解析错误?)

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

掌握 ACF 及其灵活的内容字段。

我有两个布局,如下所示,但我似乎无法让第二部分 (image_block) 正常工作,因为它不断弹出(解析错误)我可能遗漏了一些明显的东西但如果有人有一些建议,那将非常有帮助。

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

感谢任何帮助。

这是一个直接的 PHP 解析错误,与 ACF 或灵活字段无关。

请参阅我认为您缺少结尾的评论。在这些情况下,最好的办法是逐行检查你的代码,注意你从哪里开始条件以及你是否正确结束它(所以块是嵌套的)。

还要检查 HTML 元素的格式是否正确。似乎有一个额外的结束 div 标记 - 请参阅代码中的注释。

<?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> <!-- THIS closing div tag seems to be spurious -->

    <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 endif; //THIS IS WHAT NEEDS TO BE ADDED CHECK IT IS IN THE RIGHT PLACE ?>

    <?php endwhile; ?>
<?php endif; ?>