解析错误:语法错误,意外的文件结束,但没有错误


Parse error: syntax error, unexpected end of file but there is no error

这是我的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">" rel="bookmark" title=" & lt;/div>& lt;/div>& lt;/div>& lt; ?php其他:比;& lt;div id ="row2"比;& lt;div id = " tile风格= "背景图片:& lt; ?返回$tumbUrl;?在"& lt; ?php endif;?在祝辞& lt;/div>& lt;div id = " text" class="tiletext">" rel="bookmark" title="a & lt;/div>& lt;/div>& lt;/div>& lt; ?phpendif;endwhile;比;& lt;/section>之前
 
注意:确保结束标记(;)在那里,并且需要空格

尝试将所有<?echo ###?>替换为<?= ### ?>。如果PHP是<则需要在PHP。ini中启用短打开标签5.4 .

aww no: <?php the_permalink() ?>

缺少分号

其中一个应该可以修复它,否则我很抱歉:/

相关文章: