这段代码用于显示相关帖子,位于我的 includes 文件夹中。
我最近从 Mac 上的本地开发环境(使用 MAMP)切换到使用 Windows 和 WAMP。
此代码块中突然出现此错误。它没有出现在我的本地 Mac 环境中,也没有出现在现场测试中。
Parse error: syntax error, unexpected 'endif' (T_ENDIF)
错误特别指向倒数第二个endif
。如果我删除它,则会抛出指向代码中最后一个 endif
的相同错误。
有什么想法吗?我尝试删除两个指定的 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; ?>
最佳答案
short_open_tag
php.ini
中可能未启用.你可以设置 short_open_tag = On
,但是为了更便携,更改:
<? endwhile; ?>
收件人:
<?php endwhile; ?>
你应该改变所有其他<?
至 <?php
.
来自 PHP tags :
Note:
As short tags can be disabled it is recommended to only use the normal tags (
<?php ?>
and<?= ?>
) to maximize compatibility.
关于php - 最近的解析错误 : syntax error, 意外 'endif' (T_ENDIF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20153295/