WordPress函数:get_header(获取头部)

果然,过了一会儿,在那个地方出现了太阳的小半边脸,红是红得很,却没有亮光。太阳像负着什么重担似的,慢慢儿,一纵一纵地,使劲儿向上升。

描述

从当前主题中引入 header.php 模板文件。如果名字是特定的,那么包含特定名称的头部文件 header-{name}.php 就会被引入。

如果主题没有 header.php 文件,就会引入默认文件 wp-includes/theme-compat/header.php

用法

1
<?php get_header( $name ); ?>

<?php get_header( $name ); ?>

参数

$name
(string) (可选) 调用 header-name.php.

默认: None

例子

简单的 404 页面

下面的代码是一个简单模板文件,专门用来显示 "HTTP 404: Not Found" 错误的 (这个文件应该包含在你的主题中,名为 404.php

1
2
3
4
<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

<?php get_header(); ?> <h2>Error 404 - Not Found</h2> <?php get_sidebar(); ?> <?php get_footer(); ?>

多种头部

为不同的页面显示不同的头部

1
2
3
4
5
6
7
8
9
<?php
if ( is_home() ) :
	get_header( 'home' );
elseif ( is_404() ) :
	get_header( '404' );
else :
	get_header();
endif;
?>

<?php if ( is_home() ) : get_header( 'home' ); elseif ( is_404() ) : get_header( '404' ); else : get_header(); endif; ?>

这些为 home 和 404 准备的头部应该分别命名为  header-home.phpheader-404.php

资源文件

get_header() 包含在 wp-includes/general-template.php.

相关函数

get_footer(), get_sidebar(), get_template_part(), get_search_form(),comments_template()

以上就是WordPress函数:get_header(获取头部)。嫉妒,是一个人发自心底地对另一个人最大的认可。更多关于WordPress函数:get_header(获取头部)请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
WordPress站点Gravatar头像前后台不显示的如何解决办法

WordPress主题需要支持https吗?WordPress站点如何如何实现https?

WordPress站点的页面/标签/分类URL地址如何添加.html?

WordPress站点更换了域名后数据库应该如何操作替换新旧域名?

WordPress安装在主机空间的什么目录里面?根目录在哪里?