解析错误:语法错误,wp get_footer上的意外$ end

时间:2013-05-26 13:29:10

标签: php wordpress php-parse-error

我开始制作模板......

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

  </div>
  </div>
<?php

  get_footer();

?>

(这是index.php,好的,很简单。

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

(这是footer.php) 我真的在这里看不到任何错误,但我得到“Parse error:syntax error,unexpected $ end”

3 个答案:

答案 0 :(得分:1)

您忘记了endwhile;endif;语句。 alternative PHP syntax需要特定的xend;语句。

从手册中引用:

  

PHP为其某些控制结构提供了另一种语法;即,if,while,for,foreach和switch。在每种情况下,替代语法的基本形式是将左大括号更改为冒号(:),并将结束大括号分别更改为endif;,endwhile;,endfor;,endforeach;或endswitch;。

特别是:

if ():
    ...
endif;

while ():
    ...
endwhile;

答案 1 :(得分:1)

您必须为if&amp;添加添加终止语句while - endifif endwhile while的{​​{1}}。

希望这有助于!!

答案 2 :(得分:-2)

使用此功能关闭endififs

    <?php get_header();?>
     <div id="box-posts">
       <?php if (have_posts()): ?>
       <?php while (have_posts()): the_post(); ?>
       <?php endwhile; ?>
       <?php else: ?>
       <p>sorry no results</p>
        <?php endif; ?>
     </div>
  </div>

        <?php get_footer(); ?>