Home >Backend Development >PHP Tutorial >How to introduce template files in WordPress theme production, wordpress template_PHP tutorial
get_template_part() is used to reference template files, similar to get_header(), get_sidebar() and get_footer(), But this get_template_part() can introduce files with custom names.
How to use
get_template_part( $slug, $name );
Parameters
$slug
(String) (required) The file name of the template to be imported, excluding the suffix .php, that is, if you need to import the loop.php file $slug in the current theme root directory, just fill in "loop".
Default: None
$name
(String) (optional) The sub-file name of the template file to be imported. If you want to import the loop-img.php file in the current theme root directory, fill in "loop" for the $slug parameter and "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