Home > Software design >  Parse error: syntax error, unexpected token "endwhile" when upgrading PHP to 8.0
Parse error: syntax error, unexpected token "endwhile" when upgrading PHP to 8.0

Time:11-21

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.

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 >
            <div >
                <div ></div>
                <div >
                    <div style="position:absolute;bottom:0px;left:0;z-index:-10;width:100vw;height:1200px;">
                        <div >
                            <iframe  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 >
            <div >
                <div ></div>
                <div >
                    <div  style="position:absolute;bottom:0;left:0;z-index:-10;width:100vw;overflow:hidden;">
                        <video autoplay playsinline muted id="v2projectvideo"  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 >
            <div >
                <div ></div>
                <div >
                    <div  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 >
            <div >
                <div ></div>
                <div >
                    <div  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 >
            <div >
                <div >
                    <div >
                        <div ></div>
                    </div>
                    <div >
                        <div >
                            <div >
                                <p >CLIENT
                                    <span ><?php echo $theprojectclientname; ?></span></p>
                                <p ><?php echo get_post_meta($post->ID, '_client_headline', true); ?></p>
                            </div>
                        </div>
                    </div>
                    <div >
                        <div ></div>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>
    <div >
        <?php the_content(); ?>
    </div>
    <?php //echo do_shortcode('[Related_projects]'); ?><?php endwhile; ?>
<?php //get_sidebar(); ?>
<?php get_footer(); ?>```

CodePudding user response:

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

  • Related