Home  >  Article  >  Backend Development  >  WordPress主题制作之模板文件的引入方法

WordPress主题制作之模板文件的引入方法

PHPz
PHPzOriginal
2016-05-16 20:01:381407browse

get_template_part() 用来引用模板文件,类似于 get_header()、get_sidebar() 和 get_footer(),只不过这个 get_template_part() 可以引入自定义名字的文件。

使用方法

get_template_part( $slug, $name );

参数

$slug

(字符串)(必须)要引入的模板的文件名,不包括后缀名 .php,也就是如果需要引入当前主题根目录的 loop.php 文件 $slug 填写 “loop” 即可。

默认:None

$name

(字符串)(可选)要引入的模板的文件的副文件名,如果要引入当前主题根目录的 loop-img.php 文件 $slug 参数填写 “loop”,$name 参数填写 “img”。

默认值:None

返回值

此函数无返回值。

例子

引入当前主题根目录的 endskin.com 文件:

get_template_part( 'endskin' );

引入当前主题 part 目录的 loop.php 文件:

get_template_part( 'part/loop' );

引入当前主题根目录的 endskin-com.php 文件:

get_template_part( 'endskin', 'com' );

此函数位于:wp-includes/general-template.php

更多相关教程请访问 php编程从入门到精通全套视频教程

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn