Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Create a child theme based on an existing parent theme in WordPress and change the functionality, presentation, or styling of your website. In this course, author Morten Rand-Hendriksen shows how to use the default WordPress theme, Twenty Twelve, as a basis for a new child theme and add custom menus; new headers, sidebars, and footers; and index pages with widgets and pagination to your site. The course also demonstrates how to add a responsive welcome message to your front page using PHP and jQuery, and how to edit the many templates found in a WordPress theme. Morten explains how to perform these changes using any code editor, the developer tools in the Chrome browser, and WordPress.
One of the key components of any WordPress site is the index pages. Simply put, an index page shows a list of posts from the site depending on what you're asking for. The most well-known of the index pages is the blog page, which displays all the posts of the site in reverse chorological order. Other index pages include category index and archive indexes. The index pages in a WordPress theme or child theme live in a hierarchy and kick in at different times. Understanding which index page template handles and displays what content will help you customize the look and feel of your site and also avoid a lot of frustration when things don't display the way you intended.
If you look at this graphic of the WordPress template hierarchy, you can see how the different index pages kick in and when they kick in. What happens when you display any page in WordPress is the database and the browser cooperate to figure out what template to use. For example, if we're looking at a category page, this is what would happen. WordPress would say, "What kind of page is it?" It's an archive page and it's a category archive. "All right, do we have a file named category- and then the slug for this category, or the name for the category? If not, do we have a template called category- and then the number ID for that template? If not, do we have a file called category.php?" Chances are you do, and in that case we're going to use that category.php template.
The same goes for custom taxonomies, tags, author archives, date archives, and general archives. Looking at the 2012 folder, you'll see we have most of these different index page templates already in existence. We have the archive template; we have the author index template, the category index template. And if we scroll down, you'll see we have the regular index template. We also have a tag index template and even a search index template. All of these templates kick in when those specific types of content are asked for.
So let's take a look at how they work exactly. If you look at the index.php template, you see that off the very top, you have a commented-out section that explains what this template does, and it even has a link right to that graphic of the template hierarchy in WordPress. If you look at the body, you'll see exactly what happens when you use an index template. WordPress says, while you have posts, show each of the posts using the following template content. This means it's looking for a file called content- and then the name of the post format.
In older themes you won't see this get_template_part call; instead, you'll see the actual code to display all the contents for each post. But more recent themes use this function because it becomes easier to manage. So what happens here is, for each post we're actually calling this file called content and then we're displaying the content from that file. We need to look at content.php as well. You can see here, inside 2012, that we have a file called content.php and then we also have content files for each of the main post formats, aside, image, link, and so on.
We even have one for page. If we look at content, you'll see that all that happens here inside the loop is we display the content for each post. We get the post thumbnail, we get the title, we get the comments link, and we get either an excerpt or the contents, depending on what type of archive this is. So as you can see, just like with the page templates, the index page templates work in collaboration with the content templates to display all the content.
Understanding how the index pages work will help you come up with, and implement, new and exciting ways to display content. More importantly though, it'll help you troubleshoot potential problems when something doesn't display the way you intended, because now that you know how the template structure works, you can track down the correct template and make changes to that template when things aren't displaying correctly.
Find answers to the most frequently asked questions about WordPress 3: Building Child Themes.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.