【问题标题】:Parse error: syntax error, unexpected end of file but there is no error [closed]解析错误:语法错误,文件意外结束但没有错误[关闭]
【发布时间】:2013-03-17 10:51:45
【问题描述】:

这是我的 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)

【问题讨论】:

    标签: wordpress wordpress-theming php


    【解决方案1】:

    它非常简单。您使用简短的开放标签&lt;?

    在您的 php.ini 中启用简短的开放标签,或者在较新的 PHP 版本中使用完整的 php 标签,例如 &lt;?php,默认情况下禁用。但是你不应该在你的项目中使用简短的语法,如果你共享你的代码会导致问题。

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

    【讨论】:

    • short_open_tag = ON 但错误是一样的! (原来是OFF,我把它改成了ON
    • “在较新的 PHP 版本中默认禁用” - 什么?
    • 通常在您的 php.ini 中有多个值。搜索第二个值。
    • @Jueecy 看看我的链接 ;) PHP
    • 第一个是评论,只有两个short_open_tag
    【解决方案2】:

    尝试将所有&lt;?echo ###?&gt; 替换为&lt;?= ### ?&gt;。或者,如果您的 PHP 是 ,则需要在 php.ini 中启用短打开标记。

    aww no:&lt;?php the_permalink() ?&gt; 中缺少分号

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

    【讨论】:

    • 你看到我的编辑了吗? the_permalink() 处缺少 2 个分号
    【解决方案3】:

    这是修改后的工作代码...

    ID)); } 如果(我
    style="background-image:">
    style="background-image:">
    节>
    注意:确保结束标记(;)在那里以及所需的空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-03
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 2013-01-23
      • 2017-06-25
      • 2014-04-02
      相关资源
      最近更新 更多