函数文档

get_singular_template()

💡 云策文档标注

概述

get_singular_template() 函数用于获取当前或父模板中单数模板的路径。它基于 get_query_template() 实现,并允许通过动态钩子过滤模板层次和路径。

关键要点

  • 返回单数模板文件的完整路径字符串。
  • 通过动态钩子 'singular_template_hierarchy' 和 'singular_template' 可过滤模板层次和路径。
  • 内部调用 get_query_template('singular') 实现功能。
  • 自 WordPress 4.3.0 版本引入。

代码示例

function get_singular_template() {
	return get_query_template( 'singular' );
}

📄 原文内容

Retrieves the path of the singular 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 ‘singular’.

See also

Return

string Full path to singular template file.

Source

function get_singular_template() {
	return get_query_template( 'singular' );
}

Changelog

Version Description
4.3.0 Introduced.