我是一名网站开发新手,现在正在探索wordpress模板。它们都有类似的结构。但我注意到了一个让我感兴趣的有趣的事情。
在php模板文件中有函数调用,比如get_header(),get_footer()
。但我不明白PHP解释器是如何知道这些函数的存在的,因为没有任何的includes或requires……
这是如何工作的,请解释一下。我会非常感激任何帮助。
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
",这只是开始。阅读文档:
...
get_header()
位于 wp-includes/general-template.php。
来源:http://codex.wordpress.org/Function_Reference/get_header
...
get_footer()
位于 wp-includes/general-template.php。
来源:http://codex.wordpress.org/Function_Reference/get_footer
您可以在WordPress开发中获得帮助。
PHP模板文件本身被包含在某个地方。例如:
function get_header() { /* ... */ }
include("page.php");
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.
grep -r "function get_header(" *
返回定义了 get_header() 函数的文件列表。