自由屋推书网—热门的小说推荐平台!

你的位置: 首页 > wordpress标签

wordpress模板文件标签get_header描述

2018-01-22 19:54:12

get_header描述

包含当前主题目录中的header.php模板文件。如果指定了一个名字,那么将会包含一个专门的头文件header- {name} .php。
如果主题不包含header.php文件,则将包含默认主题wp-includes / theme-compat / header.php中的标题。

用法

<?php get_header($ name); ?>
参数
$name

(字符串)(可选)调用header-name.php。

默认:无

例子

简单的404页面

下面的代码是“HTTP 404:Not Found”错误(您可以在主题中包含404.php)的模板的简单示例。

<?php get_header(); ?>

<h2>错误404 - 未找到</ 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.php和header-404.php。

笔记

用途:locate_template()

用途:do_action()调用“get_header”动作。

更改日志

从以下版本开始:1.5.0

2.7.0:添加了“名称”参数。

源文件

get_header()位于wp-includes / general-template.php中。

编辑推荐

热门小说