php 怎么知道 wordpress 的函数
How does php know about wordpress functions
我是网络开发的新手。我现在正在发现 wordpress 模板。它们都有相似的结构。但是我注意到一件对我来说很有趣的事情。
php 个模板文件中有函数调用。喜欢get_header(), get_footer()
。但我不明白 PHP 解释器是如何知道这个函数的,没有任何 includes,requires ....
这是如何工作的,请解释一下。如果有任何帮助,我将不胜感激。
php 模板文件本身包含在某处。例如:
function get_header() { /* ... */ }
include("page.php");
在加载模板之前,wordpress 主题中的所有功能都已在 Wordpress 核心代码的其他地方声明。
阅读文档:
...
get_header()
is located in wp-includes/general-template.php.
来源:http://codex.wordpress.org/Function_Reference/get_header
...
get_footer()
is located in wp-includes/general-template.php.
来源:http://codex.wordpress.org/Function_Reference/get_footer
您或许可以获得有关 WordPress Development 的帮助。
查看 Wordpress 文件夹中以 index.php 开头的文件,这是第一个加载的文件。您将看到“require( dirname( __FILE__ ) . '/wp-blog-header.php' );
”,而这只是开始。
所以为了回答你的问题,wordpress 使用“require”来包含文件。
get_header()
定义在wp-includes/general-template.php.
那么wp-includes/general-template.php是如何包含的呢?
wp-settings.php requires wp-includes/general-template.php.
wp-config.php requires wp-settings.php.
wp-load.php requires wp-config.php.
wp-blog-header.php requires wp-load.php.
index.php requires wp-blog-header.php.
每个页面请求都以加载 index.php 开始。
如果您使用的是 Linux,您可以使用 grep 查找对文件的引用。例如
grep -r "function get_header(" *
returns 定义了 get_header() 函数的文件列表。
我是网络开发的新手。我现在正在发现 wordpress 模板。它们都有相似的结构。但是我注意到一件对我来说很有趣的事情。
php 个模板文件中有函数调用。喜欢get_header(), get_footer()
。但我不明白 PHP 解释器是如何知道这个函数的,没有任何 includes,requires ....
这是如何工作的,请解释一下。如果有任何帮助,我将不胜感激。
php 模板文件本身包含在某处。例如:
function get_header() { /* ... */ }
include("page.php");
在加载模板之前,wordpress 主题中的所有功能都已在 Wordpress 核心代码的其他地方声明。
阅读文档:
...
get_header()
is located in wp-includes/general-template.php.
来源:http://codex.wordpress.org/Function_Reference/get_header
...
get_footer()
is located in wp-includes/general-template.php.
来源:http://codex.wordpress.org/Function_Reference/get_footer
您或许可以获得有关 WordPress Development 的帮助。
查看 Wordpress 文件夹中以 index.php 开头的文件,这是第一个加载的文件。您将看到“require( dirname( __FILE__ ) . '/wp-blog-header.php' );
”,而这只是开始。
所以为了回答你的问题,wordpress 使用“require”来包含文件。
get_header()
定义在wp-includes/general-template.php.
那么wp-includes/general-template.php是如何包含的呢?
wp-settings.php requires wp-includes/general-template.php.
wp-config.php requires wp-settings.php.
wp-load.php requires wp-config.php.
wp-blog-header.php requires wp-load.php.
index.php requires wp-blog-header.php.
每个页面请求都以加载 index.php 开始。
如果您使用的是 Linux,您可以使用 grep 查找对文件的引用。例如
grep -r "function get_header(" *
returns 定义了 get_header() 函数的文件列表。