最近的解析错误:语法错误,意外的“endif"(T_ENDIF) [英] Recent Parse error: syntax error, unexpected 'endif' (T_ENDIF)

查看:72
本文介绍了最近的解析错误:语法错误,意外的“endif"(T_ENDIF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This bit of code is for displaying related posts and resides in my includes folder.

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

I have recently switched from a local development environment on a Mac (using MAMP) to using Windows with WAMP.

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

Suddenly this error is occurring in this block of code. It did not occur on my local Mac environment, nor does it occur when testing live.

解析错误:语法错误,意外的endif"(T_ENDIF)

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

错误具体指向倒数第二个endif.如果我删除它,则会引发指向代码中最后一个 endif 的相同错误.

The error specifically points to the second to last endif. If I remove it the same error is thrown pointing to the last endif in the code.

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

Any ideas? I tried removing both of the specified endif; statements and it throws the following error instead:

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

Parse error: syntax error, unexpected end of file

<?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,但是为了更便携,请更改:

short_open_tag is probably not enabled in php.ini. You could set short_open_tag = On, however to be more portable, change:

  <? endwhile; ?>

致:

  <?php endwhile; ?>

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

And you should change all other <? to <?php.

来自 PHP 标签:

注意:

由于可以禁用短标签,因此建议仅使用普通标签()最大限度地提高兼容性.

As short tags can be disabled it is recommended to only use the normal tags (<?php ?> and <?= ?>) to maximize compatibility.

这篇关于最近的解析错误:语法错误,意外的“endif"(T_ENDIF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆