Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]

I’ve inherited a custom template via a new client and have a piece of code that I can’t get past. It’s working fine on the live server but I can’t get the site to load on my local setup because I keep getting this error:

Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in template-welcome.php on line 88

The original developer says it matches the code in his file and he’s not having any issues with it so I’m quite perplexed.

I’m running XAMPP on Windows. If I comment out the first endwhile statement I get the same error but refering to a line lower down in the code. I think that the endwhile has been uncoupled from the if statement but I can’t see how to fix it.

Any advice? The section of code, from the original if to the endwhile statement, is copied below.

<?php
// check if the repeater field has rows of data
if (have_rows('sections')):
    // loop through the rows of data
    $section_counter = 1;
    while (have_rows('sections')) : the_row();
        ?>
        <div class="row">
            <div class="col-md-12">
                <h3 class="heading"><?php the_sub_field('section_title'); ?></h3>
                <?php the_sub_field('section_content'); ?>
                <?
                $section_slider_images = get_sub_field('section_slider');
                ?>
                <div class="home-section-slider owl-carousel owl-theme">
                    <?php
                    foreach ($section_slider_images as $image) {
                        ?>
                        <div class="item"><img class="lazyOwl"
                             data-src="https://wordpress.stackexchange.com/questions/305899/<?php echo $image["url']; ?>"
                                  alt="https://wordpress.stackexchange.com/questions/305899/<?php echo $image["alt']; ?>"
                                  title="https://wordpress.stackexchange.com/questions/305899/<?php echo $image["title']; ?>"></div>
                        <?
                    }
                    ?>
                </div>
            </div>
        </div>
        <?php
        $section_counter++;
    endwhile;
else :
    // no rows found
endif;
?>

1 Answer
1

Check your short_open_tag setting in php.ini. You have a mixture in this code. If the setting is switched off, it may be that the statements using short tags are not being parsed.

This, in particular, maybe causing the loops to be “out of sync”

                        <?
                }
                ?>

If short_open_tags is off, the foreach loop will not be looped and encounter an endwhile prematurely.

Leave a Comment