worpress引入头部文件方法:<?php get_header(); ?>
这是个 WordPress 主题系统特别用来导入 header.php 文件的函数,而不用使用 PHP 的函数:<?php include (TEMPLATEPATH . ‘/header.php’); ?>.
用法解析:
默认不带$name参数,若指定$name则表示引入指定的文件作为wp的头部文件,如:
if ( is_home() ) :
get_header( 'home' );//指定用header-home.php作为首页的头部文件
elseif ( is_404() ) :
get_header( 'single' );//指定用header-single.php作为文章页的头部文件
else :
get_header();
endif;
?>
若指定$name参数,则对应的header-{$name}.php文件名的文件必须存在,否则会忽略该参数,自动引用header.php文件,如果header.php文件也不存在,最终会引用wp-includes/theme-compat/header.php文件。
相同用法的wp方法有:get_sidebar()、get_footer()等。