Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parse error: syntax error, unexpected token "endwhile" when upgrading PHP to 8.0

I recently tried to update my website PHP to 8.0 but I am getting the following error on one of my templates:

"Parse error: syntax error, unexpected token "endwhile" on line 118."

When I revert back to PHP 7.4 it starts working again but I know it is soon to become obsolete.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please find the code below:

Any help would be greatly appreciated!

Thanks

/**
 * The template for displaying all single posts and attachments
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */

get_header('projects');

while (have_posts()) : the_post();
    
    $visibilty = get_post_meta($post->ID, '_visibilty', true);
    
    if ($visibilty == 'yes') {
        ?>
        
        <h2 style="text-align:center; padding:90px 0;">Sorry this is Confidential Page</h2>
        <?php
        exit();
    }
    $thebgimage = '';
    if(function_exists('top_image_get_meta')){
        $thebgimage = wp_get_attachment_image_src(top_image_get_meta('_top_image_id'), 'full');
    }
    
    $vimeovideoid = get_field('project_video_vimeo_id', $post->ID);
    $self_hosted_mp4 = get_field('project_video_sh_mp4', $post->ID);
    $self_hosted_webm = get_field('project_video_sh_webm', $post->ID);
    $self_hosted_still = get_field('project_video_sh_still', $post->ID);
    
    if (isset($vimeovideoid) && !empty($vimeovideoid)) { ?>
        
        <div class="work-top">
            <div class="grid">
                <div class="grid-sizer"></div>
                <div class="grid-item grid-item--width3 grid-item--height2">
                    <div style="position:absolute;bottom:0px;left:0;z-index:-10;width:100vw;height:1200px;">
                        <div class="vimeo-wrapper">
                            <iframe class="gridvid" src="https://player.vimeo.com/video/<?php echo $vimeovideoid; ?>?background=1&autoplay=1&loop=1&byline=0&title=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <?php
    } elseif (isset($self_hosted_mp4) && !empty($self_hosted_mp4) && isset($self_hosted_still) && !empty($self_hosted_still)) {
        ?>
        
        <div class="work-top">
            <div class="grid">
                <div class="grid-sizer"></div>
                <div class="grid-item grid-item--width3 grid-item--height2">
                    <div class="vid-wrapper" style="position:absolute;bottom:0;left:0;z-index:-10;width:100vw;overflow:hidden;">
                        <video autoplay playsinline muted id="v2projectvideo" class="gridvidself" poster="<?php echo $self_hosted_still; ?>" style="opacity:1;object-fit:fill;display:block;position:absolute;left:50%;transform:translate(-50%, 0);" loop>
                            <source src="<?php echo $self_hosted_mp4; ?>" type="video/mp4"><?php if (isset($self_hosted_webm) && !empty($self_hosted_webm)) { ?>
                                <source src="<?php echo $self_hosted_webm; ?>" type="video/webm"><? } ?></video>
                    </div>
                </div>
            </div>
        </div>
        
        <?php
    } elseif (substr($thebgimage[0], -13) !== 'get_start.jpg' && $thebgimage[0] != '') {
        ?>
        <div class="work-top">
            <div class="grid">
                <div class="grid-sizer"></div>
                <div class="grid-item grid-item--width3 grid-item--height2">
                    <div class="grid-inner" style="background-image:url(<?php echo $thebgimage[0]; ?>);"></div>
                </div>
            </div>
        </div>
        <?php
    } elseif (has_post_thumbnail()) {
        $bg_img = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_id()), "full");
        
        ?>
        
        <div class="work-top">
            <div class="grid">
                <div class="grid-sizer"></div>
                <div class="grid-item grid-item--width3 grid-item--height2">
                    <div class="grid-inner" style="background-image:url(<?php echo $bg_img[0]; ?>);"></div>
                </div>
            </div>
        </div>
    <?php } ?><?php
    $theprojectclientname = get_post_meta($post->ID, '_client_name', true);
    if ($theprojectclientname != '') { ?>
        <section class="kc_row project-text ptop90 clearfix">
            <div class="kc-row-container">
                <div class="kc-wrap-columns">
                    <div class="kc-elm kc-css-891324 kc_col-sm-3 kc_column kc_col-sm-3">
                        <div class="kc-col-container"></div>
                    </div>
                    <div class="kc-elm kc-css-119619 kc_col-sm-6 kc_column kc_col-sm-6">
                        <div class="kc-col-container">
                            <div class="kc-elm kc-css-609049 kc_text_block">
                                <p class="projectclient">CLIENT
                                    <span class="projectclientname"><?php echo $theprojectclientname; ?></span></p>
                                <p class="projectheadline"><?php echo get_post_meta($post->ID, '_client_headline', true); ?></p>
                            </div>
                        </div>
                    </div>
                    <div class="kc-elm kc-css-144440 kc_col-sm-3 kc_column kc_col-sm-3">
                        <div class="kc-col-container"></div>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>
    <div class="work-body">
        <?php the_content(); ?>
    </div>
    <?php //echo do_shortcode('[Related_projects]'); ?><?php endwhile; ?>
<?php //get_sidebar(); ?>
<?php get_footer(); ?>```

>Solution :

There is one line, where you are using the single open tag <? instead of <?php. Single open tags are removed with PHP 8.0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading