WordPress函数:get_footer
一、函数简介
引入当前主题的页脚文件 footer.php,如果使用特定的名字,那么就会调用这个特定名字的页脚文件 footer-{name}.php 。
如果主题没有 footer.php 就会引入默认的 wp-includes/theme-compat/footer.php 。
<?php get_footer( $name ); ?>
二、函数参数
- $name (string) (可选) 调用 footer-name.php. 默认: None
三、函数案例
(一)、404页面
下面的代码是一个简单的404页面模板 "HTTP 404: Not Found" (它应该包含在你的主题中,名为 404.php)
<h2>Error 404 - Not Found</h2>
<?php get_footer(); ?>
(二)、多个页脚
首页和404页面的专用页脚应该分别命名为 footer-home.php 和 footer-404.php 。
<?php
if ( is_home() ) :
get_footer( 'home' );
elseif ( is_404() ) :
get_footer( '404' );
else :
get_footer();
endif;
?>
四、调试效果
五、源代码
/**
* Loads footer template.
*
* Includes the footer template for a theme or if a name is specified then a
* specialized footer will be included.
*
* For the parameter, if the file is called "footer-special.php" then specify
* "special".
*
* @since 1.5.0
* @since 5.5.0 A return value was added.
* @since 5.5.0 The `$args` parameter was added.
*
* @param string|null $name The name of the specialized footer. Default null.
* @param array $args Optional. Additional arguments passed to the footer template.
* Default empty array.
* @return void|false Void on success, false if the template does not exist.
*/
function get_footer( $name = null, $args = array() ) {
/**
* Fires before the footer template file is loaded.
*
* @since 2.1.0
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
*
* @param string|null $name Name of the specific footer file to use. Null for the default footer.
* @param array $args Additional arguments passed to the footer template.
*/
do_action( 'get_footer', $name, $args );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "footer-{$name}.php";
}
$templates[] = 'footer.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
return false;
}
}
THE END