When developing a theme for WordPress, we talked about the importance of a good theme header, the header.php file. This includes not just the mast head of the HTML document that you see, but also the head tag, which includes the doctype, title, CSS links, and more.
Likewise, it is important to close with a strong footer. This will include both the visible footer to your website, assuming that it has one, but also close any tags you opened in your header. These would include any containers, as well the body and html tags.
Additionally, you will probably want to have a a div to clear out any remaining floats, or define that for your footer class/id in your CSS document.
As before, it is good to have strong comments so you can tell that closing tag goes with what section. Likewise, you will probably want to include PHP comments in the PHP sections of the file.
A typical footer.php would look something like the following:
The HTML, as you can see, is relatively simple at this point. It can get more complicated of course, but it doesn’t need to be, especially when considering the header.php file.
Here we have a clear class applied to a div, to ensure that no floats on images, or other floated content.
After that there is a closing div to a tag used to wrap the content and sidebar area. Along with that, is the footer tag, and closing it, and the body and html tags.
The PHP is also simple, but very important. We know of the echo tag from previous examples like a look into PHP. Additionally we see some PHP, and WordPress specific, functions.
The date function is part of the PHP language. It is used to display the date, as you might expect. However, how the date is displayed depends upon the parameters that are passed to the function. So you can display, for example, just the year, as we’ve done in our example, or the date with the day of the week, month, day, etc.
Look at the link provided above to see all the different ways you can display the date.
This information is not automatically written. This allows it to be stored in a variable, or written into the HTML stream via the echo command.
This function is found within WordPress itself, is similar to htmlspecialchars, which is a PHP function.
It id designed to convert text found within the string passed to it into HTML safe strings. So if you were to pass <strong>Look’s like Bold</strong>, you could get the HTML equivalent, <strong>Look’s like Bold</strong>.
This function also returns a value, so you will have to use the echo command to write the function out.
This function is special to WordPress. As you can assume, it gets information about the blog. Based up the settings that you as an Administrator setup about your blog, this function will look at those settings, and get the value.
It knows which value to get, based upon the parameter passed to the function. This function also returns a value, so you will have to use the echo command to write the function out.
This will also clean up some other aspects of the page, which is why it normally is put near the end of the HTML document. It should be included in every theme.