0

我正在尝试在 WordPress 中创建自定义表单。表单的第 1 步是 HTML 代码,它收集数据并通过 post 方法将其发送到 PHP 文件,然后将其写入 MySQL 数据库并使用 PHP 代码创建表单的第 2 步。我的问题是我想在步骤 1 中 WordPress 使用的表单的步骤 2 中包含默认的 WordPress 页眉和页脚。有没有办法通过在我的 PHP 脚本中包含 header.php 和 footer.php 的代码来做到这一点?

4

1 回答 1

1

你是这个意思?

<?php get_header(); ?>

对于页脚:

<?php get_footer(); ?>

如果你看一下get_header() function

 function get_header( $name = null ) {
        /**
         * Fires before the header template file is loaded.
         *
         * The hook allows a specific header template file to be used in place of the
         * default header template file. If your file is called header-new.php,
         * you would specify the filename in the hook as get_header( 'new' ).
         *
         * @since 2.1.0
         * @since 2.8.0 $name parameter added.
         *
         * @param string $name Name of the specific header file to use.
         */
        do_action( 'get_header', $name );

        $templates = array();
        $name = (string) $name;
        if ( '' !== $name ) {
                $templates[] = "header-{$name}.php";
        }

        $templates[] = 'header.php';

        locate_template( $templates, true );
}

你的根主题上至少有一个 header.php 文件吗?

一个常见的 Wordpress 结构:

your_project_folder
    -wp-admin
    -wp-content
        -languages
        -plugins
        -themes
            -YOUR_THEME_FOLDER
                -[HERE YOU PLACE YOUR index.php file and header.php for example, and inside index.php you place your get_header() function]
        -upgrade
        -uploads
    -wp-includes
    index.php
    wp-activate.php
    wp-blog-header.php
    wp-comments-post.php
    wp-config.php
    wp-cron.php
    [...more files]
于 2016-10-05T14:46:30.883 回答