【问题标题】:Edit database won't display when including wordpress header/footer on page在页面上包含 wordpress 页眉/页脚时,不会显示编辑数据库
【发布时间】:2012-10-19 05:11:16
【问题描述】:

我使用的是wordpress网站,但是对于网站的一部分,我决定手动连接数据库,基本上绕过wordpress来编辑数据库和检索结果。

问题是,当我包含 WP 页眉和页脚时,我得到一个空白页,虽然我无法理解,但查看源代码会出错。

这是页面显示的源代码:

<!DOCTYPE html> <!--[if IE 6]> <html id="ie6" <br /> <font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function language_attributes() in C:\wamp\www\thurston\wp-content\themes\twentyeleven\header.php on line <i>15</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0013</td><td bgcolor='#eeeeec' align='right'>388104</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\thurston\wp-content\themes\twentyeleven\editdb.php' bgcolor='#eeeeec'>..\editdb.php<b>:</b>0</td></tr> <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0024</td><td bgcolor='#eeeeec' align='right'>438352</td><td bgcolor='#eeeeec'>require( <font color='#00bb00'>'C:\wamp\www\thurston\wp-content\themes\twentyeleven\header.php'</font> )</td><td title='C:\wamp\www\thurston\wp-content\themes\twentyeleven\editdb.php' bgcolor='#eeeeec'>..\editdb.php<b>:</b>3</td></tr> </table></font>

抱歉混乱,但仅此而已。

实际页面的代码是这样的(链接到它,因为本网站的代码功能不起作用):

https://dl.dropbox.com/u/10062971/editdb.php

还有wordpress标题:

https://dl.dropbox.com/u/10062971/header.php

添加到数据库,然后在主页上显示来自数据库的信息,只需单击编辑并转到问题所在的editdb.php页面。

有人有什么想法吗?

【问题讨论】:

    标签: php database wordpress edit


    【解决方案1】:

    language_attributes() 位于 wp-includes/general-template.php。

    您不能只包含 header.php 和 foter.php 并希望获得最好的结果。您必须包含所有依赖项。

    在 [myAnchorText] 之类的页面中插入锚文本,使用输出缓冲来捕获最终的 HTML 并替换锚文本:

    <?php
    // example from php.net
    function callback($buffer) {
      // replace all the apples with oranges
      //or whatever logic you have
      return (str_replace("[myAnchorText]", "oranges", $buffer));
    }
    ob_start("callback");
    ?>
    <html><body>
    <p>It's like comparing apples to oranges.</p>
    </body></html>
    <?php ob_end_flush(); ?>
    /* output:
       <html><body>
       <p>It's like comparing oranges to oranges.</p>
       </body></html>
    */
    

    【讨论】:

    • 或多或少。您将 php 文件中的逻辑放在回调函数中。并用所需的输出替换锚。 $buffer 包含由 wordpress 生成的页面的 html 代码...您只需要插入代码(html)即可显示您的表格或任何您想要的内容
    • 这是最原始的,没有干涉 wordpress 的东西......你可以编写一个插件并以优雅的方式完成它。 :)
    • 我是 PHP 的超级新手,我不知道从哪里开始。
    • 代码似乎不起作用,不确定我做错了什么,或者我做对了什么。
    猜你喜欢
    • 1970-01-01
    • 2016-06-25
    • 2019-02-28
    • 1970-01-01
    • 2014-06-24
    • 2016-11-06
    • 2016-01-06
    • 2013-05-22
    • 1970-01-01
    相关资源
    最近更新 更多