Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Identifying Necessary Templates2:49 with Zac Gordon
A template in WordPress is a single page of markup and code that is used to display multiple pages, for example, one blog post template would be used to display all blog posts on the site. Before we begin coding, we will go over how templates work in a Content Management System, specifically WordPress.
For project files please refer to the first video: Reviewing the HTML Prototype
Basic Templates We Will Use
In this project, we will work with six primary templates:
- Homepage - front-page.php
- About and Contact - page.php
- Blog - home.php
- Blog Post - single.php
- Work - work.php
- Work Project - single-project.php
In WordPress, a template controls what content is displayed on a page
and what markup is used.
While a template generates the HTML displayed in the browser,
it does not itself contain any content.
A template contains the major HTML structure for a page,
but where you would normally put the content in its place,
special WordPress PHP code is used.
What this means is that when you visit a WordPress post in the browser
and you look at the source code for the page,
you'll be able to see all of the HTML markup, CSS, and JS links and assets
you would expect to see had you been working with the static version of the post.
However, if we take a look at the actual WordPress code
that creates the post page, it's much simpler,
with only a few lines of code and some basic HTML markup.
Part of what makes templates simpler
is that they only contain the code that is the same on every page.
This means that the same template can be used for multiple posts.
For example, if we go to another blog post,
we can see that the content changes and the source code changes
but the template stays the same.
However, if we leave the blog section of the site
and go to the About page instead,
WordPress will use a different template to build the page content.
If we were to again go to a different section, like the work section,
we would see yet another template.
However, if we go to an individual project and then scroll through the projects,
we'll see that the template stays the same
while the source code and the content change for each page.
The general rule with templates is that all pages that display similar content
in a similar format will use the same template.
For our project, we'll have 6 template pages.
This is because we have 6 different page layouts.
The first is our homepage, which will be called front-page.php.
Next we have our About and Contact page templates,
which will be named page.php.
The main blog section of the site will have a template home.php,
and individual blog posts will use a single.php template.
For our main work section we'll have a template named work.php,
and for individual projects we'll have the template file name single-work.php.
In the coming videos, we'll go into more details about how WordPress templates work,
where this naming convention comes from,
and how to start creating our own first templates.
You need to sign up for Treehouse in order to download course files.Sign up