用户登录
用户注册

分享至

wordpressget_header

  • 作者: 胸口碎大石6260688
  • 来源: 51数据库
  • 2020-06-05

1. wordpress模版的get

您好,以下是网络给您提供的:

在 WordPress 的主题函数中,为了简化我们写诸如include这种包含文件的写法,特别为我们准备了 get_header()、get_footer()、get_sidebar()等主题模板文件包含语句。今天就备忘一下get_header()这个函数吧。

get_header函数,是我们接触 WordPress 后,最先接触的几个函数之一,到目前为止,我接触到的大部分主题,都需要用到这个函数(废话)。

函数意义详解

从当前主题调用header.php文件。是不是很简单?好吧,如果你是新手的话这里要提醒一下,这里的get和get_children()、get_category中的get略有不同之处。

get_header函数声明(定义)

之前写文章很少会写到函数定义的代码,后来自己翻看的时候发现这个习惯不太好,所以决定,只要篇幅允许,就会把函数主题贴出来,方便自己翻看。

get_header 函数,声明(定义)的位置,是在 wp=include/general-template.php 文件的第 24 – 36 行左右的位置。

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

很简单,从上面的函数声明中我们也能看出,该函数只接受一个变量作为参数。

参数解释

$name ,从上面的函数声明中我们可以看出,$name是一个字符串型变量,用来调用header的别名模板,

比如 $name = “sb”;

也就是我们这样

<?php

$name = “sb”

get_header( $name );

?>

那我我们将会调用 header-sb.php 文件作为头部文件的调用。

懂了?

总结

结合诸如get_template_part()和get_header(本函数)这种别名机制,其实我们可以轻而易举的创建出庞大的,花样繁多的、别致的……主题。后面的就是折腾了不是吗?

2. Wordpress search.php 提示get

获取模板头部文件是这个没错: get_header(); 1.是不是模板中没有header.php这个文件?2.是不是想在插件输出页面中使用网页模板样式?这个方法不可行。

3.自定义页面可以通过在文件开头做以下标记包含到模板中,通过新建页面实现:<?php template="" name:="" 测试页面*/?="">4.只要不是在模板所包含文件中使用此函数都基本上都会出错,以下几个文件名称是固定不可更改的:index.php header.php footer.php archive.php single.php search.php sidebar.php comments.php style.css。

3. wordpress问题:Fatal error: Call to undefined function get

获取模板头部文件是这个没错: get_header();

1.是不是模板中没有header.php这个文件?

2.是不是想在插件输出页面中使用网页模板样式?这个方法不可行。

3.自定义页面可以通过在文件开头做以下标记包含到模板中,通过新建页面实现:

Template Name: 测试页面

*/

?>

4.只要不是在模板所包含文件中使用此函数都基本上都会出错,以下几个文件名称是固定不可更改的:

index.php header.php footer.php archive.php single.php search.php sidebar.php comments.php style.css

4. getHeader();getHeaderNames();是什么意思

http协议中的请求头,具体google,一般在程序开发中没什么意义。

wordpress使用的是PHP语言的开源系统,我们都知道PHP经常会使用到include来引用PHP文件,wordpress为了简化这些常用文件的引用,特别为我们准备了 get_header()、get_footer()、get_sidebar()等主题模板文件包含语句。get_header()函数是我们主题开发过程必用的函数,一般用于包含公用的头部文件header.php,如果你有多个头部文件你可以使用get_header($name)来获取指定头部文件header-{$name}.php。

转载请注明出处51数据库 » wordpressget_header

软件
前端设计
程序设计
Java相关