Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In a previous movie, I showed you the custom front page template and how it has separate wigitized areas, or sidebars, than the regular page templates. In the widgets area you can actually see it in the back end. You have the Main Sidebar, which is what appears on posts and regular pages, and then you have this First Front Page Widget Area and Second Front Page Widget Area, that only appear under the custom page template when that template is being used. Thanks to the WordPress template hierarchy, we can make custom templates to suit pretty much any need. This includes making custom header, sidebar, and footer templates that appear only when we want them to.
In the Twenty Twelve theme, we already see one such custom template, which is one that kicks in this, First Front Page Widget Area and Second Front Page Widget Area. Let's take a look at that template. If you look at the twentytwelve theme and we will scroll down to the bottom here, you see we have two templates; we have sidebar and sidebar-fronts. If you look at sidebar, you see all it does is call the sidebar-1, which is the main sidebar.
If you look at sidebar-fronts you'll see the same thing happens except here we are calling sidebar-2 and sidebar-3. These correspond with these First Front Page Widget Area and Second Front Page Widget Areas. But where do they come from? Well if you look at the page template, when we scroll all the way to the bottom, you see here it says get_sidebar; this is a general call, if I called the sidebar.php page. It's the same type of call you used to call the footer.phpfile, get_footer, and also the header.php file, get_header.
But if you go back to twentytwelve and go into page templates, the folder, and open the front page custom page template, you see that instead of just calling get_sidebar, we're adding a variable, front. This tells WordPress that instead of calling sidebar.php it should be calling sidebar-front.php. So that's how the custom sidebar kicks in, in a custom page template. Now you have a clear idea of the naming structure and how this works, and it's actually really simple.
If you want to create a custom header, footer, or sidebar at any point in your site, all you do is as you create a custom file called header- and then give it the name that you want to use, and then to call it, you simply go get_header then define that same name. The same goes for sidebar and footer as well. This is what actually happens. If we use the regular page.php template, we have the function call get_header that calls the header.php template.
However, if we decided to create custom header file that we only wanted to appear in our no-title-page template, we would add get_header parentheses custom in our function, and that would call the header-custom.php file instead. The same exact technique applies to sidebar.php and footer.php as well. By utilizing the built-in functionality of the template hierarchy, you can create custom layouts and content displays on pretty much any page on your site.
This allows you to add and subtract content in areas like the header, sidebar, footer, depending on what page, post, or index the visitor lands on, and that can in turn be used to give the visitor a more meaningful and informational experience when visiting your site.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.