Fatal Error: get_header();

时间:2014-04-09 作者:Shah

致命错误:调用未定义的函数get\\u header()

我不能让它工作。我使用wordpress附带的213个默认主题。我创建了一个名为table.php 我还使用了<?php template name ?>. 这个自定义模板只显示数据库中的所有记录。它工作正常,但缺少页眉和页脚,当我试图通过添加get_headerget_footer, 它抛出一个致命错误。代码如下:

我要说的是,我曾经index.php 它位于Twenty13文件夹中,而不是根文件夹中wp-config 文件或任何其他index.php 就这点而言。

<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * @link http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

get_header(); ?>



<DIV class="form">

        <form method = "post"  action="<?php echo get_stylesheet_directory_uri(); ?>/dbentry.php">
            First Name: <input type="text" name = "first">*<?php echo $first_error;?><br>

            Last Name: <input type="text" name = "last">*<?php echo $last_error; ?><br>

            Email: &nbsp &nbsp &nbsp &nbsp    <input type="text" name = "email"><br>
            Telephone: <input type="number" name = "telephone">*<?php echo $tele_error; ?><br>

            Gender:&nbsp &nbsp 
            <input type="radio" name = "gender" value = "female">Female
            <input type="radio" name = "gender" value = "male">Male
            <br>

            <input type="submit" value ="submit" name="submit"><br>


        </form>
 </DIV>    

        <form action="<?php echo get_stylesheet_directory_uri(); ?>/tab.php"     method="post">
            <input type="submit" name = \'submit2\' value = \'http://localhost/wordpress/?page_id=11\'>
        </form>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Here is the code where the call will go after pressing the "Show all records" button.

<?php
    /**
     * The template for displaying all pages
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages and that other
     * \'pages\' on your WordPress site will use a different template.
     *
     * @package WordPress
     * @subpackage Twenty_Thirteen
     * @since Twenty Thirteen 1.0
     */

     /* 
     Template name: tab
     */

    get_header(); ?>

    <div class="table">
        <table class = "border">
            <?php

               require "db.php";

               if(isset($_POST[\'submit2\'])){
                    $query = "SELECT * FROM person";
                    $result = mysqli_query($connection, $query);
                    $row = \'\';
                    $id = "";
                    echo "<tr>";
                    echo "<th><b>ID</b></th>";
                    echo "<th><b>FIRST</b></th>";
                    echo "<th><b>LAST</b></th>";
                    echo "<th><b>EMAIL</b></th>";
                    echo "<th><b>TELEPHONE</b></th>";
                    echo "<th><b>GENDER</b></th>";
                    echo "<th  scope=\'row\'>EDIT</th>";
                    echo "<th>DELETE</th>";
                    echo "</tr>";
            echo "<tr>this is working just fine</tr>";
                    while($row = mysqli_fetch_array($result)){
                        $id = $row[\'ID\'];
            echo $id ;

                        echo "<tr><td>".$row[\'ID\']."</td><td>".$row[\'First\']."</td><td>".$row[\'Last\']."</td><td>".$row[\'Email\']."</td><td>".$row[\'Telephone\'].
                        "</td><td>".$row[\'Gender\']."</td><td>"."<a href=\'edit.php?ID=$id\'><input type=\'button\' class = \'edit\' value = \'Edit\'></a>"."</td><td>"."<a href=\'delete.php?ID=$id\'><input type=\'button\' class = \'del\' value=\'Delete\'></a>"."</td></tr>";

                    }

                    mysqli_close($connection);

               } 
            ?>
        </table>
    </div>

    <table>
        <tr>jsdnsdjnsjd</tr>
    </table>



        <form action="form.php" method="post">
        <input type="submit" name="new" value="New Entry" class = "new">
        </form>




    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

2 个回复
SO网友:Milo

无法直接加载模板文件。WordPress未在该上下文中加载,因此您无法访问其功能。在WordPress admin中创建一个页面,并将模板分配给该页面,然后将链接指向该页面,而不是直接指向模板文件。

结束

相关推荐

当我尝试登录时,我正在创建的插件出现‘Headers Always Sent’错误

我正在尝试创建我的第一个插件。到目前为止,它实际上工作正常,但有一个错误:当我尝试登录到wp admin时,会收到一条“Headers ready Sent”PHP消息。如果我从wpcontent/plugins目录中删除插件文件,像往常一样登录,然后替换插件文件,它工作得很好——这似乎只是在登录和注销时发生的。我的(缩写)代码是:<?php /* Plugin Name: Product Manager Plugin URI: http://www.tech-knowled