首页 WordPress函数 WordPress加载头部模板标签:get_header
正文 评论

WordPress加载头部模板标签:get_header

WordPress模板标签get_header用来加载头部模板,即header.php

get_header( string $name = null )

get_header标签默认加载header.php,但可以通过传递一个参数来实现加载类似header-name.php的模板:

<?php get_header(\'name\'); ?>

以上示例加载header-name.php模板,如果header-name.php文件不存在,则加载header.php,这样就为没有header-name.php文件时提供了一个备用选项。

我们可以通过页面判断来为不同页面加载不同的头部模板:

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

以上示例为首页加载header-home.php,为404页面加载header-404.php,其他页面加载header.php

我们还可以为分类和标签页加载不同的头部模板:

<?phpif ( is_category() ) :get_header( \'category\' );elseif ( is_tag() ) :get_header( \'tag\' );else :get_header();endif;?>

以上示例为分类页加载header-category.php,为标签页加载header-tag.php

如果你掌握了WordPress条件标签的用法,可以充分发挥你的想像力,定制出个性化的主题。

扩展阅读

get_header()函数位于:wp-includes/general-template.php

相关函数:

  • get_sidebar()
  • get_template_part()
  • get_search_form()
  • comments_template()
  • get_footer()
-=||=-收藏赞 (0)
更多主题
v1.0.0
小程序收录免费WordPress主题:XCX主题
¥ 0 关注:22,481
详情
单栏极简文艺WordPress博客主题:Diaspora主题
¥ 0 关注:22,055
详情
简约黑白WordPress个人博客主题:Personal主题
¥ 0 关注:21,760
详情
功能丰富切轻量的WordPress虚拟资源主题:Rizhuti主题
¥ 599 关注:19,807
详情
v1.0.0
一款简约单栏的免费WordPress博客主题:itheme主题
¥ 0 关注:19,737
详情
v3.4.0
适用自媒体资讯的免费WordPress主题:Autumn主题
¥ 0 关注:16,836
详情
回复
暂无评论

不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。