PHP解析错误:语法错误,第26行/wp-content/themes/awaken/page.php中的意外'endwhile'(T_ENDWHILE)

时间:2016-05-25 20:41:48

标签: php wordpress parsing

我有错误日志

  

PHP Parse错误:语法错误,意外'endwhile'(T_ENDWHILE)in   /wp-content/themes/awaken/page.php   在第26行

my page.php

get_header(); ?>
<div class="row">
<?php is_rtl() ? $rtl = 'awaken-rtl' : $rtl = ''; ?>
<div class="col-xs-12 col-sm-12 col-md-8 <?php echo $rtl ?>">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page' ); ?>
                <?php if ( get_theme_mod( 'display_page_comments', 1 ) ) { // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : comments_template(); endif; } ?>
            <?php endwhile; // end of the loop. ?>
        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .bootstrap cols -->
<div class="col-xs-12 col-sm-6 col-md-4">
    <?php get_sidebar(); ?>
</div><!-- .bootstrap cols -->
</div><!-- .row -->
<?php get_footer(); ?>

请帮忙! 我有503错误,认为这是一个问题

2 个答案:

答案 0 :(得分:1)

不要混合使用常规语法和扩展语法,特别是当你有可怕的缩进时。注意代码看起来如何没有所有重复/无意义的php打开/关闭标记:

while ( have_posts() ) : the_post();
   if ( get_theme_mod( 'display_page_comments', 1 ) ) { // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : comments_template(); endif; }
      endwhile; // end of the loop

由于您已注释掉if的部分内容,因此您永远不会关闭{,这意味着您最终会尝试终止一段时间不存在。

答案 1 :(得分:0)

你看到了吗?我做。您已经注释掉了代码,并顺便将结束括号添加到if( get_theme_mod。这是一个简单的语法错误。

<?php if ( get_theme_mod( 'display_page_comments', 1 ) ) { // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : comments_template(); endif; } ?>

需要改为

 <?php if ( get_theme_mod( 'display_page_comments', 1 ) ) { 
     // If comments are open or we have at least one comment, load up the comment template 
     if ( comments_open() || '0' != get_comments_number() ) : 
         comments_template();        
     endif; 
 } ?>

如果您不想要评论模板,那么只需注释掉//comments_template();

这样做的原因是你添加的内联评论会注释掉它没有选择的整个line,并选择它应该注释掉的部分以及它应该让解释器处理的部分。

相关问题