【问题标题】:Html does parsing error in my index.php (wordpress theme) [duplicate]Html在我的index.php(wordpress主题)中解析错误[重复]
【发布时间】:2015-11-16 11:44:51
【问题描述】:

我正在构建自己的 wordpress 主题。我对 html 和页面相关的东西并不陌生,但从未为 php 编写代码行。我想继续使用更复杂的 cms - wordpress。现在我不明白为什么,但我的页面由于某种原因抛出了解析错误。

解析错误:语法错误,意外 ... 在 ## 行

这是我的部分代码,包括 php 中的 html:

     <?php

     if (have_posts()) :
        while (have_posts()) : the_post();

        <h2>Title here</h2> /* says error is on this line */

        endwhile;

        else :
            echo '<p>No content found</p>'

        endif; /* also error is on this line */

     ?>

我正在使用 Dreamweaver,但我猜这不是解决此问题的关键。

【问题讨论】:

    标签: php html wordpress parse-error


    【解决方案1】:
    <?php
    
         if (have_posts()) :
            while (have_posts()) : the_post();
    ?>
            <h2>Title here</h2> /* says error is on this line */
    <?php
            endwhile;
    
            else :
                echo '<p>No content found</p>'
    
            endif; /* also error is on this line */
    
         ?>
    

    这会对你有所帮助....

    【讨论】:

    • Thx 这几乎解决了它,但在 endif 上仍然存在一些意外错误; ://
    • 好吧,少了分号:D 对不起,谢谢大家给我最快的帮助:D 喜欢这个网站!
    【解决方案2】:

    试试这个。缺少一个回声和分号。

    if (have_posts()) :
        while (have_posts()) : the_post();
    
        echo '<h2>Title here</h2>'; /* says error is on this line */
    
        endwhile;
    
        else :
            echo '<p>No content found</p>';
    
        endif; /* also error is on this line */
    

    【讨论】:

    • 好的,非常感谢。这肯定会解决它。但是 wordpress 应该能够完全支持 php docs 中的 html :/ 你能帮我解决这个问题吗?
    • 对不起,我对 wordpress 没那么自信。我刚刚检查了语法。
    • 谢谢 :) 我还不能 +1,但如果可以的话我会给你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 2015-09-08
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    相关资源
    最近更新 更多