这是我的php代码的一个wordpress主题的index.php:
<section id="content">
<?php
$i=1;
while(have_posts() && i < 7):the_post();
$tumbUrl = '';
if(has_post_thumbnail())
{
$tumbUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
}
if(i < 4):
?>
<div id="row1">
<div id="tile<?echo $i?>" class="tile">
<div id="img<?echo $i?>" class="tileimage"<?if($tumbUrl != ''):?> style="background-image:<?echo $tumbUrl; ?>"<?endif;?>></div>
<div id="text<?echo $i?>" class="tiletext"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
</div>
</div>
<?
else:
?>
<div id="row2">
<div id="tile<?echo $i?>" class="tile">
<div id="img<?echo $i?>" class="tileimage"<?if($tumbUrl != ''):?> style="background-image:<?echo $tumbUrl; ?>"<?endif;?>></div>
<div id="text<?echo $i?>" class="tiletext"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
</div>
</div>
<?
endif;
endwhile;
?>
</section>
,当我想运行它时,我得到错误说Parse error: syntax error, unexpected end of file in C:'wamp'www'wordpress'wp-content'themes'Odatis'index.php on line 31
,但我找不到任何错误。
很简单。使用简短的开放标签<?
。
在php.ini中启用短的打开标签,或者在较新的php版本中使用完整的php标签,如<?php
,默认情况下是禁用的。但是你不应该在你的项目中使用简短的语法,如果你共享你的代码,可能会导致问题。
http://www.php.net/manual/en/ini.core.php ini.short-open-tag
下面是修改后的工作代码…
<>之前& lt; id ="内容"部分比;& lt; ?phpi = 1美元;While (have_posts() && I <7): the_post ();$tumbUrl = ";如果(has_post_thumbnail ()){$tumbUrl = wp_get_attachment_url(get_post_thumbnail_id($post->ID));}如果我& lt;4):比;& lt;div id ="第一行"比;& lt;div id = " tile风格= "背景图片:& lt; ?返回$tumbUrl;?在"& lt; ?php endif;?在祝辞& lt;/div>& lt;div id = " text" class="tiletext">