将WordPress页眉和页脚添加到PHP脚本

时间:2016-10-05 14:43:04

标签: php mysql wordpress get-headers

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

1 个答案:

答案 0 :(得分: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]