get_footer()导入footer.php文件

目录

描述

 

  • 导入footer.php文件。
  • 如果设置了参数 $name ,则会导入footer-{name}.php文件。
  • 如果主题文件夹中没有footer-{name}.php文件,则导入wordpress默认主题的sidebar.php文件(wp-includes/theme-compat/footer.php)。

get_footer() 描述

用法

<?php get_footer$name ); ?>

get_footer() 用法

参数

$name

(string) (可选) Calls for footer-name.php.

默认值: None

get_footer() 参数

返回值

None.

get_footer() 返回值

示例

Simple 404 page

The following code is a simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Mullti footers

Different footer for different pages.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php
if ( is_home() ) :
	get_footer( 'home' );
elseif ( is_404() ) :
	get_footer( '404' );
else :
	get_footer();
endif;
?>

The file names for the home and 404 footers should be footer-home.php and footer-404.php respectively.

get_footer() 示例

注意

get_footer() 注意

历史

  • 添加于 版本: 1.5.0
  • 2.7.0 : 添加 'name' 参数.

get_footer() 历史

源文件

get_footer() 函数的代码位于 wp-includes/general-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Load footer template.
 *
 * Includes the footer template for a theme or if a name is specified then a
 * specialised footer will be included.
 *
 * For the parameter, if the file is called "footer-special.php" then specify
 * "special".
 *
 * @since 1.5.0
 *
 * @param string $name The name of the specialised footer.
 */
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 $name Name of the specific footer file to use.
	 */
	do_action( 'get_footer', $name );

	$templates = array();
	$name = (string) $name;
	if ( '' !== $name )
		$templates[] = "footer-{$name}.php";

	$templates[] = 'footer.php';

	// Backward compat code will be removed in a future release
	if ('' == locate_template($templates, true))
		load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
}

get_footer() 源文件

相关