Connecting the Templates in WordPress Twenty Fifteen - dummies

Connecting the Templates in WordPress Twenty Fifteen

By Lisa Sabin-Wilson

WordPress has built-in functions to include the main template files, such as header.php, sidebar.php, and footer.php, in other templates. An include function is a custom PHP function that’s built in to WordPress allowing you to retrieve the content of one template file and display it along with the content of another template file. Check out the templates and the function to include them.

Template Name Include Function
header.php <?php get_header(); ?>
sidebar.php <?php get_sidebar(); ?>
footer.php <?php get_footer(); ?>
search.php <?php get_search_form();
?>
comments.php <?php comments_template();
?>

If you want to include a file that doesn’t have a built-in include function, you need a different piece of code. For instance, if you want to add a unique sidebar (different from the default sidebar.php file within your existing theme) to a certain page template, you can name the sidebar file sidebar-page.php. To include that in another template, you use the following code:

<?php get_template_part( ‘sidebar’, ‘page’ ); ?>

In this statement, the PHP get_template_part function looks through the main theme folder for the sidebar-page.php file and displays the content from the sidebar-page.php file. If it does not find that file, WordPress defaults to displaying the sidebar.php file.

You will need to put together the guts of a basic Main Index template. There seem to be endless lines of code when you view the loop.php template file in the Twenty Fifteen theme, but it’s not as intimidating as it seems.