【问题标题】:Parse error: syntax error, unexpected $end on wp get_footer [closed]解析错误:语法错误,wp get_footer 上的意外 $end [关闭]
【发布时间】:2013-05-26 13:29:09
【问题描述】:

我开始构建模板并...

<?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) 我真的看不出这里有什么问题,但我得到“解析错误:语法错误,意外 $end”

【问题讨论】:

  • -1 因为这个问题没有显示任何研究工作;不清楚或没用。关闭后我也会投票删除它。

标签: php wordpress php-parse-error


【解决方案1】:

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

引用手册:

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

特别是:

if ():
    ...
endif;

while ():
    ...
endwhile;

【讨论】:

  • 哦,原来如此。很抱歉,这是一个非常愚蠢的问题。感谢您的快速回复。
【解决方案2】:

您必须为ifwhile 添加添加终止语句 - 即endif 用于ifendwhile 用于while

希望这会有所帮助!

【讨论】:

    【解决方案3】:

    使用它来关闭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(); ?>
    

    【讨论】:

    • 正确,但不是解析错误的原因。
    • @Polygnome 这是错误之一。那为什么要投反对票
    • 我没有投反对票,但这不是“为什么我会收到此解析错误”问题的答案。
    • @Polygnome 和 Jeffrey 现在没事了
    • 不,这是错误的。只是因为我有一个
      在标题上未关闭。不过还是谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-08-15
    • 2014-08-08
    • 1970-01-01
    • 2014-04-02
    • 2011-10-26
    • 2014-09-02
    • 2014-04-26
    • 1970-01-01
    相关资源
    最近更新 更多