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

PHPz
Release: 2018-10-11 15:15:43
Original
1416 people have browsed it

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

使用方法

get_template_part( $slug, $name );
Copy after login

参数

$slug

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

默认:None

$name

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

默认值:None

返回值

此函数无返回值。

例子

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

get_template_part( 'endskin' );
Copy after login

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

get_template_part( 'part/loop' );
Copy after login

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

get_template_part( 'endskin', 'com' );
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!