外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>WordPress开发>WordPress函数:get_header(获取头部)

WordPress函数:get_header(获取头部)

描述

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

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

用法

<?php get_header( $name ); ?> 

参数

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

默认: None

例子

简单的 404 页面

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

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

多种头部

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

<?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()

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
WordPress开发

WordPress中文文档:模板入门

2013-4-4 10:46:00

WordPress开发

WordPress函数:get_sidebar(获取侧边栏)

2013-4-4 12:15:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索