最近的分析错误:语法错误,意外';endif';(T_ENDIF)


Recent Parse error: syntax error, unexpected 'endif' (T_ENDIF)

这段代码用于显示相关帖子,位于我的includes文件夹中。

我最近从Mac上的本地开发环境(使用MAMP)切换到使用带有WAMP的Windows。

突然,这个错误出现在这个代码块中。它没有发生在我的本地Mac环境中,也没有在现场测试时发生。

分析错误:语法错误,意外的"endif"(T_endif)

该错误特别指向倒数第二个endif。如果我删除它,则会抛出指向代码中最后一个endif的相同错误。

有什么想法吗?我尝试删除两个指定的endif;语句,但它却抛出了以下错误:

分析错误:语法错误,文件意外结束

<?php  
  $orig_post = $post;  
  global $post;  
  $tags = wp_get_post_tags($post->ID);  
?>
<?php if ($tags):  ?>
<?php  
  $tag_ids = array();  
  foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;  
  $args=array(  
  'tag__in' => $tag_ids,  
  'post__not_in' => array($post->ID),  
  'posts_per_page'=>3, // Number of related posts to display.  
  'caller_get_posts'=>1 ,
  'post_type' => array( 'post', 'featured-wedding' )
  );  
  $my_query = new wp_query( $args );  
?>
<?php if($my_query->have_posts()): ?>  
    <aside class="related group">
      <h2>You May Also Like:</h2>
      <?php while( $my_query->have_posts() ) : $my_query->the_post(); ?>
        <a href="<? the_permalink()?>">
            <!-- thumbnail -->
            <?php the_post_thumbnail(array(175,175)); ?>
            <!-- post title -->
            <?php if ( 'featured-wedding' == get_post_type() ) : ?>
              <h1>Featured Wedding: <?php the_title(); ?></h1>
            <?php else: ?>
              <h1><?php the_title(); ?>: <?php if (function_exists('the_subheading')) { the_subheading('<span>', '</span>'); } ?></h1>
            <?php endif; ?>
        </a>    
      <? endwhile; ?>
    </aside> 
<?php endif; ?>
<?php  
  $post = $orig_post;  
  wp_reset_query();  
 ?>  
<?php endif; ?>

short_open_tag可能未在php.ini中启用。您可以设置short_open_tag = On,但要更便携,请更改:

  <? endwhile; ?>

收件人:

  <?php endwhile; ?>

您应该将所有其他<?更改为<?php

来自PHP标签:

注意

由于可以禁用短标签,建议仅使用普通标签(<?php ?><?= ?>)以最大限度地提高兼容性。

您可以将php.ini中的short_open_tag从OFF更改为ON,并且无需更改所有未添加<?php的文件(请不要忘记在更改php.ini后重新启动服务器(Apache、Nginx)。)

您可以将php.ini中的short_open_tag从OFF更改为ON,并且无需更改所有未添加<?php的文件(不要忘记在更改php.ini之后重新启动服务器(Apache、Nginx)。)