Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m

Next lesson playing in 5 seconds


Free Preview: Coding Advanced WordPress Theme Templates


  • Overview
  • Transcript

Template files are at the heart of every WordPress theme. And if you've already gotten started creating WordPress themes, chances are you have some experience with coding template files. But there's always more to learn!

In this course, you'll learn how to customize your themes with advanced theme templates. You'll see how to create an advanced WordPress theme for a blog. Along the way, you'll learn different ways to code the Loop, how to create templates for custom page and post types, how to create templates for custom taxonomies, and how to use conditional tags to make your templates more flexible.

Do you want to learn WordPress development from start to finish? Check out our learning guide: Learn WordPress Development.

1 lesson, 00:37

Free Lesson

2.Making Use of Include Files
2 lessons, 16:58

Free Lesson
Review of Standard Include Files

Creating Multiple Loop Files

3.Creating Custom Template Files
2 lessons, 16:25

Custom Page Templates

Templates for Custom Content

4.Conditional Tags
1 lesson, 06:37

Using Conditional Tags to Output Content

1 lesson, 02:58


1. Introduction

1.1 Introduction

Hello, and welcome to this Tuts Plus course on Coding Advanced Theme Templates in WordPress. My name's Rachel McCollin. In this course, I'll show you how to take a standard theme and make it more bespoke with additional theme templates. So I'll show you how to create extra loop files and include files, and how to call them correctly. I'll also show you how to create a custom page template for our contact page. And then finally, I'll show you how to create a single page for a new post type, as well as a new archive page for a new custom taxonomy. Watch this course and find out how to create advanced theme templates.

2. Making Use of Include Files

2.1 Review of Standard Include Files

Hello and welcome back to this Tuts+ course on coding advanced theme templates. In the next few parts of the course we'll be looking at include files. And in this part of the course I'm gonna take you through the include files we already have in our theme, and show you what they do and how they work. So here's a dummy site I've set up on my local machine to demonstrate the parts in this course. And this is running a fairly basic theme that I've created that will show all the techniques that you learned in our introductory course on creating WordPress Themes. Now let's have a look at the files in our theme, so here it is in Coda, and these are all the files that it has. So you can see there's an index.php, there's a page.php, and a single.php, so those are displaying different types of content. There's also an archive.php file for archives, a functions file for all the functions in our theme. And that includes all of the code we need to set up the theme, and setu up the widget areas as well. And then there's some include files. Now you'll notice that I've got one of these in its own separate include folder. And that's because, later on in the course, I'll be creating more files in this folder, and it's handy to keep them separate. But I'll come back to this one in a moment. The three include files that are fairly standard to a WordPress theme, it's very unusual not to use them, are header, sidebar, and footer. So let's start with header, so here's the header file. This contains everything from the opening head section to the beginning of the body, and right down through to the header, which you can see here, and then to my navigation. So that's everything, going back to the site, here in my header and in my navigation. And then the individual template files will display the content. And then the sidebar will be displayed by its own include file, as I'll show you shortly. So in every template file, let's take a look at index.php, there is this call to get the header, php get_header. And you'll be familiar with that if you've been building any themes. The other include files we have are sidebar.php, which includes our widget area, so you can see that over here. Footer.php, and in this case I've got three widget areas in my footer. And that file is called in my index file by the get_footer function. So there's get_sidebar here for the sidebar, get_footer for the footer, and right up here, get_header. Now just going back to that footer, you'll see that it also, after closing the actual footer itself, so our widget area, let's take a look back at our site and see those widgets. As well as the footer itself on the page, it runs the wp_footer hook which has to be included in every theme. It closes the body tag, and then it closes the HTML tag, so it closes off the page completely. And the equivalent of this wp_footer hook up in the header is wp_head. So you have to make sure that you include wp_head and wp_footer in the right place in all of your themes. And the reason for that is because lots of WordPress functionality is hooked to those, and lots of plugins hooked to those as well, and you'll find things break if you haven't got them. So let's have a look at the final include file, and that's our loop. Now in index.php it's called here, within the content div. So we've got a content div on the left-hand side that's two-thirds width, and that uses object-oriented styling in my theme in my style sheet. And then within that, we got get_template_part( 'include/loop' ). Now if your loop.php file is in the same folder as your template file, you don't have to include this includes. That tells me that it's in that subfolder, so here it is in includes > loop. So that, then, opens up the loop.php file and runs it here as if it was coded into this template file. And here's my loop, so you can see I'm checking for posts, and running a while ( have_posts() ) : the_post(), and it's a standard loop. And then within that I've got entry-meta, with the date, the_content, and then entry-utility section with comments. And then finally I'm closing my article, and I'm closing my while and if, so I'm ending the loop. So those are the standard include files that you'll have in the majority of your WordPress template files. I would strongly recommend using these, because it makes life easier in that you only have to write the code within them once. Using header, sidebar, and footer is a no-brainer, I've never seen a theme that doesn't do it. And you definitely don't want all this in every one of your theme template files, you want to only be able to edit it once. And using a loop file is also really useful. In the next part of this course we'll take that a bit further. And I'll show how to create multiple versions of the loop, and call them in different template files. See you next time, and thanks for watching.