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.
Once you start personalizing your child theme, you'll probably want to make changes to the index pages, as well as a single posts and pages. Working with the index templates require a bit more thinking on your end, but it's not any more complicated, and you can produce some pretty cool results with very little effort. In the 2012 Theme, the only thing you see under the post title is a link to the comments, as you can see right here. If you want to know who wrote the story, when it was published, or any other information, you need to scroll all the way down to the bottom of the post.
I personally don't think this makes any sense. I think the author name and the publishing date should be at the very top, along with a link to the comments. So that's what we're going to do. A little earlier in the course we took a brief look at how the index page works, so let's just quickly look back at that file. If we look at index.php, you'll see that inside the loop where we're jumping through each of the individual posts and displaying their content, what we're doing is actually using a separate file called content to display that content.
So it's this file, content.php, that we're going to change. The first step when working with a child theme is always to grab the file and copy it into your child theme. Now we can modify it without damaging the original file. When I open this file the first thing you want to find out is where the content I want to use is. Looking at the post, I see that I have a link to the comments at the very top, under the title. And looking inside my template file, I can see that we have the comments right down here.
If comments are open then display the Comments pop-up link. So this is where I need to place a new content. So I'll make some space here, just so it's easier to follow, and then I can move on. I also know that the information I want to display already exists in this template, because down here at the bottom of the page I have the date and other information. So the first thing I'm going to do is try to get all this information to display at the very top as well. Back in my template, I can scroll down. Here I find the content, which means it has to be underneath here, and underneath the content we find this footer class entry meta that has a function in it called twentytwelve_entry_meta.
This is probably the function that's inserting that content, so I'm going to test that by simply copying the function and the footer class and placing it before my comments. I'll close the footer, just to clean up the markup, and then test my page. I'll reload the page in the browser, and now I see at the top I have the same information at the top as I have in the bottom. But this is not entirely the information I want. It's a lot of information, but it's not the information I want to use.
All I need is the author name and the date. Now I know that this is generated from a function, because I can see it here, twentytwelve_entry_meta. So what I want to do now is grab some components of that function and put them into my template. The function is contained within a file called functions.php, and we'll look in more detail at functions.php later, but now we're going to get a sneak preview. I'll go to my twentytwelve folder and find functions.php. It's right here. I'll open it and go down to line 319.
And here we have that function, twentytwelve_entry_meta. Now this function does a lot of things, and I only need small components of it. What I want is the date and the author. These two functions are actually advanced functions that create two variables--date and author--and then populate those variables with the links to the date and the actual date information, and links to the author and the author information.
So I'm simply going to copy these two variables as they are and paste them into my new footer here. So I'll replace the function with this content I just copied, and I'll just clean it up a bit so that it looks better. And then I have to display the content here. So because I have the content in variables, all I have to do is say echo and then echo out the variables. So just so I see what is going on, I'm going to put in some text here.
I'll say Date:, space, and then put in the date variable, and then date variable, space, Author:, space, and then put in the author variable. I'll save this and reload my page, and now you see it says date and then a link to the date archive, and author and a link to the author archive. This is almost what I want. I don't want it to look like this, and I also wanted the Comment link to go up next to it.
So I'll go back and do some more editing. I'll change the text around here so it says By and then the name of Author. And then say punctuation mark, Published on, and the date. And then because I already have the comments here, all I'm going to do is take this code and place it into the footer and then make some small changes to it.
So I'll grab the code I need, here, cut it out, and paste that in directly underneath the line I just created. And then I already know I don't need these divs because they're the ones that are splitting these two lines. So I'm going to take the divs out, and I'll take out this redundant PHP delimiter. Save my template, reload the page, and now it says, By mor10, Published on October 16, Leave a reply.
Now if you thought it was hard to follow exactly what I did here and you are afraid of writing all this code to make sure it works, I created a code snippet for you that you can use to just paste right in. If you go to the codesnippets file in the exercise files and go down to Chapter 4.2, you'll find both the simple way--that is, just moving the function itself--and you'll also find the advanced option, where we get the date and author variables and then display them, along with the comments.
So all we have to do is copy out the entire section here from footer to end footer and paste it into content.php and you'll get the same results that I got. Here you've seen several different things: how the content.php template file interacts with multiple different other template files and uses functions from those files to display content; you've also seen how we can use existing code as building blocks to create new effects; and you've gotten a sneak peek at the functions.php file that we'll look at in more detail later.
But I want you to take away from this is any content you can see on the page you can always grab and put somewhere else in your template simply by copying wherever it comes from and placing it somewhere else.
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.