我正在尝试通过研究一些免费插件/主题来学习 WordPress 结构。
我现在正在研究“Renger博客主题”,但我无法理解一些东西。我已经检查了 WP 手册中的 get_header() 页面,但它看起来仍然很神奇:)
该主题有自定义功能代码
wordpress\wp-content\themes\renderblog\inc\renderoption.php
这个主题调用这个文件只是
get_header();
在index.php
header.php 或其他任何地方都没有包含代码。
如何使用 get_header()
调用这个特定的 PHP 文件?这是一种自动包含 inc 文件夹中所有文件的方法吗?
当我从index.php中删除get_header()
时,这些功能不起作用。
最佳答案
WordPress get_header()
是 WordPress 内置结构预定义的函数。此函数包含主题的标题模板,或者如果指定了名称,则将包含专用标题。
如果文件名为“header-new.php”,则指定“new”。
例如<?php get_header('new'); ?>
不同页面的不同标题的另一个示例。
<?php
// if detect home page of wordpress
if ( is_home() ) :
get_header( 'home' );
// if detect Not found page 404 of wordpress
elseif ( is_404() ) :
get_header( '404' );
// default header if nothing specific is detected
else :
get_header();
endif;
?>
关于php - get_header() 如何调用特定的 PHP 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51584646/