详解WordPress开发中get_header()获取头部函数的用法
《:详解WordPress开发中get_header()获取头部函数的用法》要点: 函数意义详解 get_header函数声明(定义) function get_header( $name = null ) { do_action( 'get_header',$name ); $templates = array(); if ( isset($name) ) $templates[] = "header-{$name}.php"; $templates[] = 'header.php'; // Backward compat code will be removed in a future release if ('' == locate_template($templates,true)) load_template( ABSPATH . WPINC . '/theme-compat/header.php'); } get_header函数的使用 <?php get_header( $name ); ?> 很简单,从上面的函数声明中我们也能看出,该函数只接受一个变量作为参数.PHP实例 参数解释 <?php $name = “ab” get_header( $name ); ?> 这将会挪用 header-ab.php 文件作为头部文件的挪用.PHP实例 例子:PHP实例 1.简单的 404 页面PHP实例 下面的代码是一个简单模板文件,专门用来显示 "HTTP 404: Not Found" 错误的 (这个文件应该包括在你的主题中,名为 404.php)PHP实例 <?php get_header(); ?> <h2>Error 404 - Not Found</h2> <?php get_sidebar(); ?> <?php get_footer(); ?> 2.多种头部PHP实例 为分歧的页面显示分歧的头部PHP实例 <?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 .PHP实例 编程之家培训学院每天发布《:详解WordPress开发中get_header()获取头部函数的用法》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |