php 解析错误:语法错误,WordPress 主题中出现意外的“endif”(T_ENDIF)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20153295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:55:24  来源:igfitidea点击:

Parse error: syntax error, unexpected 'endif' (T_ENDIF) in WordPress theme

phpwordpress

提问by kisabelle

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

这段代码用于显示相关帖子并驻留在我的包含文件夹中。

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

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

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.

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

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

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

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

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

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

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

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; ?>

回答by AbraCadaver

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

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

  <? endwhile; ?>

To:

到:

  <?php endwhile; ?>

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

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

回答by ??????-GEXAYR

You can change short_open_tagin php.inifrom OFF to ON and it will not be necessary to change all files in which not added <?php(do not forget to reboot the server (Apache, Nginx) after the change php.ini. )

你可以改变short_open_tagphp.ini从OFF开,并没有必要改变其没有添加的所有文件<?php(不要忘了更改后重新启动服务器(Apache时,Nginx的)php.ini。)