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

时间:2013-03-27 11:13:19

标签: wordpress wordpress-theming php

这是wordpress主题的index.php的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版本是5.4.3)

3 个答案:

答案 0 :(得分:13)

非常简单。您使用短开标签<?

php.ini 中启用短打开标记,或者在默认情况下禁用的较新PHP版本中使用完整的php标记,如<?php。但是,如果共享代码,则不应在项目中使用可能导致问题的短语法。

http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

答案 1 :(得分:2)

以下是修改后的工作代码......

<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<?php echo $i; ?>" class="tile">
            <div id="img<?php echo $i; ?>" class="tileimage"<?php if($tumbUrl != ''): ?> style="background-image:<?php echo $tumbUrl; ?>"<?php endif; ?>></div>
            <div id="text<?php echo $i; ?>" class="tiletext"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
        </div>
    </div>
    <?php 
        else:
    ?>
    <div id="row2">
        <div id="tile<?php echo $i; ?>" class="tile">
            <div id="img<?php echo $i; ?>" class="tileimage"<?php if($tumbUrl != ''): ?> style="background-image:<?php echo $tumbUrl; ?>"<?php endif; ?>></div>
            <div id="text<?php echo $i; ?>" class="tiletext"><a href="<?php the_permalink(); ?>" rel="bookmark" title="a<?php the_title(); ?>"><?php the_title(); ?></a></div>
        </div>
    </div>
    <?php 
        endif;
        endwhile;
    ?>
</section>
Note: Make sure the ending mark(;) are there and also the space as required.

答案 2 :(得分:1)

尝试将所有<?echo ###?>替换为<?= ### ?>。或者,如果你的PHP是&lt;你需要在你的php.ini中启用短开标签。 5.4。

aww否:<?php the_permalink() ?>

中缺少分号

其中一个应该解决它,否则我很抱歉:/

相关问题