php getfooter,WordPress获取页脚函数get_footer用法

重要:本文最后更新于2018-11-13 13:36:23,某些文章具有时效性,若有错误或已失效,请在下方留言或联系代码狗。

WordPress函数介绍——获取页脚函数get_footer详解。

7be258c3d0338c4c83d83c960574b3d2.png

WordPress教程

函数原型

该函数位于wp-include/general-template.php 文件的第 61 行左右的位置,代码如下。

function get_footer( $name = null ) {

/**

* Fires before the footer template file is loaded.

*

* The hook allows a specific footer template file to be used in place of the

* default footer template file. If your file is called footer-new.php,

* you would specify the filename in the hook as get_footer( 'new' ).

*

* @since 2.1.0

* @since 2.8.0 $name parameter added.

*

* @param string|null $name Name of the specific footer file to use. null for the default footer.

*/

do_action( 'get_footer', $name );

$templates = array();

$name = (string) $name;

if ( '' !== $name ) {

$templates[] = "footer-{$name}.php";

}

$templates[]    = 'footer.php';

locate_template( $templates, true );

}

使用方法

PHP函数需要使用<?php ?>包裹,调用方法为:

函数说明

由上面的函数原型可以看出,get_footer函数需要一个字符串类型参数,并且该参数允许为空,为空时查找主题目录下footer.php文件,不存在则使用默认的 wp-includes/theme-compat/footer.php 作为页脚,不为空时查找footer-参数名.php文件作为头部。

如传入daimadog

此时将加载主题目录下的footer-daimadog.php作为网站的头部文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值