Search code examples
phpwordpressphp-parse-error

Parse error: syntax error, unexpected $end on wp get_footer


I started building a template and...

<?php get_header(); ?>
  <div id="box-posts">
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>

  </div>
  </div>
<?php

  get_footer();

?>

(This was index.php, okay, it's simple.

  <div id="footer">
  <br />
  Copyright (C) 
  <br /><br />
  </div>
  </center>
  </body>
  </html>

(And this was footer.php) I really can't see anything wrong here, but i get "Parse error: syntax error, unexpected $end"


Solution

  • You have forgot the endwhile; and endif; statements. The alternative PHP syntax requires a specific xend; statement.

    Quoting from the manual:

    PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

    In particular:

    if ():
        ...
    endif;
    

    and

    while ():
        ...
    endwhile;