-1

I'm getting an error 500 and upon looking in my error logs I get this error:

PHP Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE) in /var/www/site/site.com.au/wp-content/themes/site/page.php on line 90

Line 90 is the endwhile in this code:

    <? while ( $query->have_posts() && $count != 3) : $query->the_post()?>
        <? $count++; ?>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <?php the_post_thumbnail('medium'); ?>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 post-info">
                <h3><a title="<?php echo get_the_title(); ?>" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h3>
                <time><?php the_date(); ?></time>
                <div class="category">
                <!--    <p>Category: <a title="Posts about <?php get_category_link(get_the_category()[0]->title); ?>" href="<?php echo get_category_link(get_the_category()[0]->id); ?>"><?php the_category(', ', 'single', get_the_ID()); ?></a></p>-->
                </div>
                <a title="<?php echo get_the_title(); ?>" href="<?php echo get_permalink(); ?>" class="col-12 btn btn-block btn-info">Read More..</a>
            </div>
        </div>
        <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>

Why am I getting this error after migrating from WordPress 4.7.10 to the latest WP (4.9 I think)?

I'm currently using PHP 7 on the new environment.

Oliver Kucharzewski
  • 2,523
  • 4
  • 27
  • 51

1 Answers1

2

Looks like the problem is your use of shorttags here: <? instead of <?php

If your server isn't interpreting these as PHP, php will see the endwhile before it sees the close tags. Change them to <?php instead of <?.

<?php while ( $query->have_posts() && $count != 3) : $query->the_post()?>
  <?php $count++; ?>
    <div class="row">
       <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
         <?php the_post_thumbnail('medium'); ?>
       </div>
       <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 post-info">
          <h3><a title="<?php echo get_the_title(); ?>" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h3>
          <time><?php the_date(); ?></time>
          <div class="category">
                <!--    <p>Category: <a title="Posts about <?php get_category_link(get_the_category()[0]->title); ?>" href="<?php echo get_category_link(get_the_category()[0]->id); ?>"><?php the_category(', ', 'single', get_the_ID()); ?></a></p>-->
          </div>
          <a title="<?php echo get_the_title(); ?>" href="<?php echo get_permalink(); ?>" class="col-12 btn btn-block btn-info">Read More..</a>
        </div>
    </div>
 <?php
 endwhile; //resetting the page loop
 wp_reset_query(); //resetting the page query
 ?>
Özgür Can Karagöz
  • 1,039
  • 1
  • 13
  • 32