函数原型:
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工作流
哈利波特魔法ComfyUI工作流
一只精致透明的朱红色水晶狐狸
一座精致透明的白瓷人物雕塑comfyui工作流
一个穿着发光红色长袍的人
一位美丽的女士在座机上讲话ComfyUI工作流
一个女人站在海边的岩石上,飞来一只鸟
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用css3做一个动态loading效果
自动打字效果(惊喜在后面)
canvas黑洞漩涡(canvas+js)
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
css3绘制一个会动的大嘴鸟
利用js+css3做一个小鱼游泳特效
利用CSS3代码编写45款按钮效果
如何利用svg做一个有趣的loading动画加载










