Start learning with our library of video tutorials taught by experts. Get started

WordPress 3: Building Child Themes

Adding author, date, and time information to the index loop


From:

WordPress 3: Building Child Themes

with Morten Rand-Hendriksen
Expand all | Collapse all
  1. 6m 59s
    1. Welcome
      1m 6s
    2. Using the exercise files
      1m 34s
    3. What you need to know before watching this course
      1m 29s
    4. Getting the right tools for theme creation
      2m 50s
  2. 17m 2s
    1. What is a WordPress child theme and when should you use it?
      2m 38s
    2. Picking a parent theme
      3m 55s
    3. Making sure you have the Twenty Twelve parent theme
      1m 50s
    4. Creating and activating a basic child theme
      4m 20s
    5. Importing parent theme styles
      4m 19s
  3. 16m 2s
    1. Using the developer tools
      3m 53s
    2. Modifying existing styles
      4m 24s
    3. Adding space between paragraphs
      4m 7s
    4. Changing font family styles
      3m 38s
  4. 31m 47s
    1. Understanding the WordPress template hierarchy
      3m 12s
    2. Modifying existing templates
      2m 33s
    3. Moving the header image
      4m 29s
    4. Adding Related Posts feature to posts
      6m 26s
    5. Creating custom page templates
      5m 43s
    6. Using conditional statements for customized effects
      5m 41s
    7. Creating custom header, footer, and sidebar templates
      3m 43s
  5. 17m 5s
    1. Understanding the different index pages and what they do
      4m 6s
    2. Adding author, date, and time information to the index loop
      7m 15s
    3. Changing the appearance of category index pages
      5m 44s
  6. 43m 5s
    1. Introducing functions.php
      3m 24s
    2. Overriding existing functions
      3m 23s
    3. Adding pagination to index pages
      5m 49s
    4. Adding to existing functions
      3m 21s
    5. Adding a new footer menu to Twenty Twelve
      6m 24s
    6. Adding a new widgetized area to pages
      4m 9s
    7. Adding static content to the sidebar
      7m 44s
    8. Replacing existing functions
      2m 36s
    9. Adding a Google font through a function
      6m 15s
  7. 10m 24s
    1. Adding new featured image sizes
      5m 41s
    2. Adding featured images to posts and pages
      4m 43s
  8. 31m 1s
    1. Adding a welcome message to the front page
      1m 22s
    2. Displaying page content in an index page
      7m 42s
    3. Hooking in a featured image
      4m 34s
    4. Making the welcome message responsive
      6m 27s
    5. Restricting content to the first page of the blog
      4m 22s
    6. Adding a jQuery function to show or hide the welcome message
      6m 34s
  9. 10m 23s
    1. Adding a custom favicon
      3m 58s
    2. Adding a custom screenshot
      2m 29s
    3. Adding footer information
      3m 56s
  10. 7m 14s
    1. What to do when a child theme crashes your website
      4m 38s
    2. Updating parent and child themes
      2m 36s

Video: Adding author, date, and time information to the index loop

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.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
WordPress 3: Building Child Themes
3h 11m Intermediate Jun 23, 2011 Updated Nov 27, 2012

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.

Topics include:
  • Picking a parent theme
  • Creating and activating a basic WordPress child theme
  • Using the developer tools
  • Changing the header image size
  • Using conditional statements for customized effects
  • Adding custom menus to the child theme and/or a template
  • Changing the default footer content
  • Adding featured images to posts
  • Changing the display of meta content (such as date, author, category, etc.)
  • Excluding categories from the front page with custom queries
  • Including functions from external files
  • Identifying and fixing common mistakes
Subjects:
Web CMS
Software:
WordPress
Author:
Morten Rand-Hendriksen

Adding author, date, and time information to the index loop

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.


Expand all | Collapse all
Please wait...
Q: The 2010 version of this course no longer covers installing BitNami. Can you provide directions?
A: Instructions on how to install WordPress using BitNami can be found at
 http://bitnami.org/stack/wordpress. Use the "Installer" option. 
It is pretty straight forward and almost impossible to mess up.

lynda.com also has a dedicated course on WAMP and MAMP (Installing Apache, MySQL, and PHP) that is relevant and you might find helpful.
Q:When looking to download PHP development tool at www.eclipse.org/pdt/, as advised by Morten, but when accessing the site via this link, the screenshot in the movie is very different from what it takes you to on the website.
A: Eclipse has a very active developer cycle and updates quite frequently. The interface changes all the time. I recommend using Notepad++ (Windows) or TextWrangler (Mac) instead. They perform the same function but are far less cumbersome to deal with.
Q: This course was updated on 11/27/2012. What changed?
A: This course was heavily revised to reflect changes to the default WordPress parent theme, Twenty Twelve, and updates to WordPress's functionality. The entire course was re-recorded to reflect changes to the interface. Then we added new movies on text styling, the Related Posts feature, and the welcome message features. There are also two brand new chapters, "Modifying and Adding Functions" and "Working with Featured Images." We recommend that members who have seen the whole course start again from the beginning to get the most benefit from this update.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress 3: Building Child Themes.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked