函数文档

get_home_template()

💡 云策文档标注

概述

get_home_template() 函数用于获取首页模板的完整路径,支持当前或父主题模板。它基于模板层次结构,并通过动态钩子进行过滤。

关键要点

  • 返回首页模板文件(如 home.php 或 index.php)的完整路径字符串。
  • 使用动态钩子 'home_template_hierarchy' 和 'home_template' 来过滤模板层次和路径。
  • 内部调用 get_query_template() 函数实现,传递 'home' 类型和模板数组。

代码示例

function get_home_template() {
    $templates = array( 'home.php', 'index.php' );

    return get_query_template( 'home', $templates );
}

注意事项

  • 该函数自 WordPress 1.5.0 版本引入,是模板系统的一部分。
  • 相关函数 get_query_template() 可用于获取其他类型的模板路径。

📄 原文内容

Retrieves path of home template in current or parent template.

Description

The template hierarchy and template path are filterable via the ‘$type_template_hierarchy’ and ‘$type_template’ dynamic hooks, where $type is ‘home’.

See also

Return

string Full path to home template file.

Source

function get_home_template() {
	$templates = array( 'home.php', 'index.php' );

	return get_query_template( 'home', $templates );
}

Changelog

Version Description
1.5.0 Introduced.