gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:15:07 25 4
gpt4 key购买 nike

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

最佳答案

你是说这个吗?

<?php get_header(); ?>

对于页脚:

<?php get_footer(); ?>

如果您看一下 get_header() 函数:

 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]

关于php - 将 WordPress 页眉和页脚添加到 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39877079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com