【函数介绍】
我们都知道PHP经常会使用到include来引用PHP文件,wordpress为了简化这些常用文件的引用,特别为我们准备了 get_header()、get_footer()、get_sidebar()等主题模板文件包含语句。get_header()函数是我们主题开发过程必用的函数,一般用于包含公用的头部文件header.php,如果你有多个头部文件你可以使用get_header($name)来获取指定头部文件header-{$name}.php。
【函数使用】
<?php get_header( $name ); ?>
【参数说明】
$name
(string) (可选) 获取指定头部文件,格式为header-name.php.
默认: None
【参数实例】
404页面设置:
<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
多个头部,获取主题中的头部文件header-test.php:
$name = 'test';
<?php get_header('test'); ?>