get_date_template()
云策文档标注
概述
get_date_template() 函数用于获取当前或父主题中日期模板的完整路径。它基于 WordPress 的模板层次结构,通过动态 Hook 允许过滤模板路径。
关键要点
- 函数返回日期模板文件的完整路径字符串。
- 内部调用 get_query_template('date') 实现,简化了模板检索过程。
- 模板层次结构和路径可通过动态 Hook '$type_template_hierarchy' 和 '$type_template' 进行过滤,其中 $type 为 'date'。
- 自 WordPress 1.5.0 版本引入,是核心模板函数的一部分。
代码示例
function get_date_template() {
return get_query_template( 'date' );
}注意事项
使用此函数时,需确保主题中包含符合 WordPress 模板命名约定的日期模板文件(如 date.php),否则可能返回空路径或默认模板。
原文内容
Retrieves path of date 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 ‘date’.
See also
Source
function get_date_template() {
return get_query_template( 'date' );
}
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |