Lets take a look in the twentysixteen theme.
Line 18/19 (inside the loop) of single.php
shows actualy all you need/want to know, it uses:
get_template_part( $slug, $name );
// Include the single post content template
get_template_part( 'template-parts/content', 'single' );
That means actualy for WP:
- Get a (partial) template for a (in this case) single post.
- Look in the folder (from within your
theme
directory)
template-parts
for a file which has the name
content-single.php
. - ‘Grab’ what is in it (lets say
<?php echo 'Hello World'; ?>
) and display – Hello World – ascontent
for thatpost
.
This way it already has the header
and footer
as you want it/as (imho) should be done.
There are other ways to load -templates- (through a function
) but that was not the question here.
Note: You can do this also with page.php
/ taxonomy.php
/ archive.php
/ category.php
etc.
See the codex for: Theme development
See the codex for: Linking to Core Theme Files
I hope this explains (although in a digest size) the basics of how you can use get_template_part
.