Home >Backend Development >PHP Tutorial >How to introduce template files in WordPress theme production

How to introduce template files in WordPress theme production

WBOY
WBOYOriginal
2016-07-29 09:08:421013browse

get_template_part() is used to reference template files, similar to get_header(), get_sidebar() and get_footer(), except that this get_template_part() can introduce files with custom names.

Usage

get_template_part( $slug, $name );

Parameters

$slug

(string) (required) The file name of the template to be imported, excluding the suffix name .php, that is, if you need to introduce the loop of the current theme root directory. PHP file $slug just fill in "loop".

Default: None

$name

(String) (optional) The sub-file name of the template file to be imported. If you want to introduce the loop-img.php file in the current theme root directory, fill in the $slug parameter with "loop" ", fill in "img" for the $name parameter.

Default value: None

Return value

This function has no return value.

Example

Introduce the endskin.com file in the current theme root directory:

get_template_part( 'endskin' );

Introduce the loop.php file in the current theme part directory:

get_template_part( 'part/loop' );

Introduce the endskin-com.php file in the current theme root directory:

get_template_part( 'endskin', 'com' );

Others

This function is located at: wp-includes/general-template.php

The above introduces the introduction method of template files for WordPress theme production, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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