外贸营销

wordpress函数get_header()的妙用
2019.09.06 外贸营销

wordpress函数get_header()的妙用—不同页面调用不同头部信息。
说明
该函数从当前主题文件夹中包含header.php模板文件。如果指定名称,那么函数将包含一个特殊的头部文件header-special.php。如果主题中没有header.php文件,那么函数会包含默认主题wp-content/themes/default/header.php的头部文件。

用法
<?php get_header( $name ); ?>

参数
$name

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

默认值:None

示例
包含非默认头部文件

<?php
get_header(‘myheader’);
?>

简单的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;
?>

wordpress函数get_header()的妙用—不同页面调用不同头部信息。

上一篇下一篇
标签

有问
必答