Build Your Own Business Website header image

Lesson 9 – Part 6 – Example #3 – Refine custom footer attribution with automatic copyright date and site title

Difficulty Level -

Filed Under Topics -

Listed Under Lesson Subjects -

Applies to -

Exercise number 3 is to refine this custom footer in the Thesis theme and start using PHP and HTML interspersed. Right now we have PHP and then HTML and then PHP. But what we’re going to do now is something that you will actually do regularly when you’re customizing and that is switch back and forth and back and forth between PHP and HTML.

Add Link to Home Page and Add Automatic Copyright Date

We’re going to copy this and paste it. And now instead of byob simple custom footer, the name for this function is going to be just byob custom footer. So the hook needs to have the simple removed and then we’re going to change this up. Instead of Tailoring the Web with the copyright, what we’re going to do is to put a link to the home page instead. And then we’re going to automatically calculate this end date.

WordPress Function bloginfo()

The first thing we’re going to do is use a WordPress function called blog info. Let’s come back over here to the site and actually, we can just search the codex for blog info. I have a link to blog info over here but we’re going to look for this function, blog info.

Blog info grabs a group of information about the blog and gives you the ability to print it to the screen. Blog info takes a parameter and the parameter that it takes is one of these ones. So it’s either name, description, admin, email, URL, WordPress URL, stylesheet directory, so on and so forth. Any one of these things can be returned by blog info.

Use bloginfo() to Return Home Page Link

What we want to do is return the name of our website so we’re going to use blog info with the parameter name like this. What we really want to do is to show the name but we also want to link to the name of the site and that’s what you have down here. You’ve got a link tag with blog info URL as the href with blog info name as the title and with blog info name as the link text.

Let’s start off right there by placing our link, a href equals. So there’s the href and then title equals, there’s our title. There’s the closing of that first tag. There’s the closing a tag and then what we’re going to put inside here is the website name.

We could physically put the href there and we could go to our homepage. Okay our website name and then our address, we’re going to do that. So here’s our address for this. Okay so href essentially the homepage, go to the homepage, website name and then its’ going to be copyright 2009-2012.

This is the version before we refine it. And what we’re going to do is to comment out this add action for the simple one and we’re going to let the regular custom footer kick in instead. So it’s upload, come back over here and refresh it and now, the Tailoring the Web should be missing.

Refine the Function

So this is our new function. We typed that in ourselves. Now instead of typing this in ourselves, what we’re going to do is replace that with blog info. So instead of href here, we’re going to add this blog info and what we need to do then is to open up PHP, and then recognizing that we’re going to close PHP so we do that.

Then we say blog info and then opening and closing brackets and then the parameter name. In this case, we want the URL there, right? URL. Okay so PHP blog info URL. What we’ve done is we’ve substituted that HTML for this PHP function… actually, we need that semi-colon in there so blog info URL. And now, rather than using our website name here, we’re just going to use exactly the same function in place of website name. But instead of URL, it’s going to be name.

Now we’ve got blog info URL, blog info name, title will be ‘Go to our homepage’. Hit save, upload it and then refresh it. now, it says, “Customize Thesis Like A Pro Lesson p?” Oh, look at that. I did. Instead of Lesson 9, I said Lesson p. Come over here to our Settings General, instead of Lesson P, Lesson 9. Hit save changes.

This is where it takes that. This is the site title, that’s blog info name. So there it is, Customize Thesis Like A Pro Lesson 9 Copyright 2009-2012. If you hover over it, you can see the title, “Go to our homepage.” And let’s just make sure it works, so the URL part works.

Use PHP Date Function

The next thing we’re going to do is use the PHP date function. And if we come over here to and search for date, we have our date function. The date function has a couple of parameters. It takes the format that you want the date to be displayed in and then optionally, it takes the time that you want displayed.

Now if you don’t include this second parameter, it will take the current time. So that’s what we’re going to do. We’re going to use the current time for that 2012 part of our copyright and the date has a bunch of different format characters. So if you put in a lowercase d, it will show the day of the month, 01 to 31. If you use the upper case D, it will show Monday or abbreviated, Mon or whatever through Sunday, which ever date that happens to be. If you use a lowercase j it will show the day of the month without the leading zeros.

We don’t care about the date and the time. We only care about the year. And if we come down to y’s, you can see that the lowercase y shows the year in two digits and the uppercase Y shows the year in 4 digits. That’s what we want is the uppercase Y.

So we’re going to come back over to our function here and instead of 2012, we’re going to delete that. We’ll put our opening PHP tag with our closing PHP tag and then in that, we’re going to say date, opening and closing brackets, single quotes, upper case Y and closing semi-colon. And now, what this will do is put the current year, date plus that y returns the current year. Upload it, come back over to our page and refresh it. And it’s not doing something.

Echo Statement

I forgot the echo statement. This went and got the date but we didn’t tell it to do anything with the date. Blog info automatically prints to screen. You don’t have to tell it to print to screen. That’s what blog info does. Date does not necessarily do anything except retrieve the date.. And so in this case, what we have to use is the PHP function called echo.

Let’s come back over here to the manual and we search for echo. Echo is the primary function that prints to the screen. It can print a variety of things to this screen. It can print a string which is like a sentence or for example, our “Hello World”. That is a string so as this expands, multiple lines and new lines would give output as well. That is a string.

So it can print a string to the screen. It can print the value of a variable to the screen. So if you’ve got a variable called foo and you’ve placed a foo bar as the value inside of that variable, you can say echo foo and it will print foo bar.

And it can also print a result of a function. That’s what we’re doing here, the date is a function. And so if you echo date, it’s going to echo the result of this function. Remember that little graphic I showed you of “Hello World”, echo “Hello World” that’s echoing the string. This is echoing the result of a function.

Okay so now we have this home page name and copyright automatically generated, 2012 Customize Thesis Like A Pro Lesson 9. And that completes exercise number 3.

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 Comments… add one
0 comments… add one