解析错误:语法错误,意外的文件结束,但没有错误[关闭](Parse error: syntax er

2019-07-28 07:03发布

这是一个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)

Answer 1:

它非常简单。 您可以使用短开放标记<?

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

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



Answer 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.


Answer 3:

尝试更换所有<?echo ###?><?= ### ?> 。 或者你需要启用短开放标签在你的php.ini如果你的PHP是<5.4。

噢没有:有一个分号缺失<?php the_permalink() ?>

其中一个应该修复它,否则对不起:/



文章来源: Parse error: syntax error, unexpected end of file but there is no error [closed]