0

We're movin' to a new website-host but strangely some pages won't work on the new server while working correctly on my test-machine (with another hoster).

The php-log shows:

[03-May-2024 06:53:16 UTC] PHP Parse error: syntax error, unexpected token "endwhile" in /path-to-wp/wp-content/themes/blw/single-events.php on line 76

Both machines are running php 8.2.18, and the admin of the new hoster told me it may have got sth to do with a deprecated "construct". I'm no php-dev so I don't know what this means. Maybe someone here can help me out. Would be great! :-)

<?php

/**
 * The template for displaying the event detail pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package blw
 */

get_header();
?>
<div class="container">
    <main id="primary" class="site-main">
        <?php while (have_posts()) : the_post(); ?>
            <div class="row">
                <div class="col-md-12 col-lg-8 order-lg-2" id="main_content">
                    <?php if (has_post_thumbnail($post->ID)) {
                        echo '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr($post->post_title) . '">';
                        echo get_the_post_thumbnail($post->ID, 'full');
                        echo '</a>';
                    } else {
                    ?>
                        <img src="<?php echo get_template_directory_uri() ?>/img/templates/events-empty.gif" alt="default image">
                    <?php } ?>
                    <?php if ($caption = get_post(get_post_thumbnail_id())->post_excerpt) : ?>
                        <p class="caption"><?php echo $caption; ?></p>
                    <?php endif; ?>
                    <div class="txt-box header-title">
                        <?php the_title() ?>
                    </div>
                    <div class="txt-box" id="content">
                        <?php the_field('event_title_notes') ?>
                    </div>
                    <?php $value = get_field('event_moderation');
                    if ($value) {; ?>
                        <div class="txt-box">
                            Moderation: <span><?php the_field('event_moderation') ?></span>
                        </div>
                    <?
                    } else {
                    } ?>
                    <div class="txt-box" id="content">
                        <?php the_field('event_description') ?>
                    </div>
                </div><!-- .lg-8 -->
                <div class="col-md-12 col-lg-4 order-md-1" id="sitebar">
                    <div class="event_city_term">
                        <?php
                        $terms = get_the_terms(null, 'event_city');
                        foreach ($terms as $term) {
                            echo $term->name;
                        }
                        ?>
                    </div>
                    <div class="event-date-time">
                        <?php the_field('event_date');
                        echo " | ";
                        the_field('event_time');
                        echo " Uhr"; ?>
                    </div>
                    <div class="column-header">
                        Veranstaltungsort
                    </div>
                    <div class="txt-box content">
                        <?php the_field('event_location_notes') ?>
                    </div>
                    <div class="column-header">
                        Eintritt
                    </div>
                    <div class="txt-box content">
                        <?php the_field('event_price_notes') ?>
                    </div>
                </div><!-- .lg-4 -->
            <?php
        endwhile;
            ?>
    </main><!-- #main -->
</div><!-- .row -->
</div><!-- .contaner -->

<?php
get_sidebar();
get_footer();
2
  • This is more a general PHP question than a WordPress specific one. As far as I can see the PHP is okay, though the resulting html is invalid, because the opening div to row is inside main, while the closing div is outside. To keep your code readable it is often better to write everything in PHP, by using echo statements to output html rather than closing php, writing the html and the opening php again
    – cjbj
    Commented May 3 at 8:26
  • It's not my own code, but I'll have a look. Thx for the hints. Much appreciated 🙏
    – Ralf
    Commented May 4 at 9:34

1 Answer 1

2
                <?
                } else {
                } ?>

This is your problem: PHP short opening tags were deprecated in PHP 7.4 and completely removed in 8.0, so while your old server may have had 8.2.18 installed it wasn't using it to run the site (versions of PHP can exist side by side). Replace the <? with <?php and it should work again.

1
  • 1
    Hey Chris, this was exactly the problem. Thx a lot for the timely support! Much appreciated 🙏 :-)
    – Ralf
    Commented May 4 at 9:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.