get_template_part
云策文档标注
概述
get_template_part 是一个 WordPress 钩子,在尝试定位和加载模板部分之前触发。它允许开发者在模板加载过程中执行自定义操作,常用于修改模板参数或添加额外逻辑。
关键要点
- 钩子名称:get_template_part
- 触发时机:在定位和加载模板部分之前
- 参数:$slug(模板的 slug 名称)、$name(专用模板名称或空字符串)、$templates(模板文件数组)、$args(传递给模板的额外参数数组)
- 源调用:do_action( 'get_template_part', $slug, $name, $templates, $args )
- 相关函数:get_template_part() 用于加载模板部分
- 版本变更:WordPress 5.5.0 添加了 $args 参数,5.2.0 引入此钩子
原文内容
Fires before an attempt is made to locate and load a template part.
Parameters
$slugstring-
The slug name for the generic template.
$namestring-
The name of the specialized template or an empty string if there is none.
$templatesstring[]-
Array of template files to search for, in order.
$argsarray-
Additional arguments passed to the template.
Source
do_action( 'get_template_part', $slug, $name, $templates, $args );