函数原型:
get_template_part( string $slug, string $name = null, array $args = array() ): void|false
为子主题提供一种简单的机制,以重载主题中可重用的代码部分。
包含主题的命名模板零件,或者如果指定了名称,则将包含特定的模块。如果主题不包含{slug}.php文件,那么将不包含任何模板。
该模板是使用require包含的,而不是require_one包含的,因此您可以多次包含同一个模板部分。
对于$name参数,如果文件名为“{slug}-special.php”,则应指定 $name 为:“special”。
参数说明:
$slug,模板的 $slug,比如模板文件 header.php 的$slug 是 ‘header’,footer.php 的$slug 是 ‘footer’。
$name,指定特定的模板模块。比如上文提到的 {slug}-special.php 中 $name 为:“special”。
$args,传递给模板文件的参数。
函数源码:
function get_template_part( $slug, $name = null, $args = array() ) {
do_action( "get_template_part_{$slug}", $slug, $name, $args );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "{$slug}-{$name}.php";
}
$templates[] = "{$slug}.php";
do_action( 'get_template_part', $slug, $name, $templates, $args );
if ( ! locate_template( $templates, true, false, $args ) ) {
return false;
}
}
包含钩子:
do_action( 'get_template_part', string $slug, string $name, string[] $templates, array $args )
do_action( "get_template_part_{$slug}", string $slug, string|null $name, array $args )
使用举例:
get_template_part(
'template-part',
'name',
array(
'key' => 'value',
'key2' => 'value2'
)
);
上面是“wordpress建站:怎么利用get_template_part加载模板模块文件”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4224.html
workflows工作流
一只竹节虫ComfyUI工作流
骨骼般的恶魔修女ComfyUI工作流
一位24岁的金发女海盗ComfyUI工作流
一条闪闪发光的金鱼ComfyUI工作流
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
一只巨大的极其精细的鞋子ComfyUI工作流
一座生动的点彩主义灯塔ComfyUI工作流
一个由红色玻璃制成的女性形状的破碎雕塑
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

iframe开发admin后台
3d空间行走效果
css3动画loading效果
js导出excel插件(兼容mac电脑Numbers表格)
纯css3绘制的小鸟
2023年程序猿如何给自己开启一场烟花盛会
HTML5 Canvas 刻度尺
利用css3做一个动态loading效果





