Down the WordPress Rabbit Hole
Before getting down and dirty with WordPress, I want to talk very briefly about expectations. While WordPress has a very low entry barrier for users who stick with what is provided, to become a true WordPress ninja takes years. See this wonderful piece by the inimitable Chris Lema. We don’t expect to reach that level by reading one book (affiliate link). But we can do better than we did before, and that’s a gift every day. So let’s go for it.
Today we are looking at Chapter 3, about the WordPress template hierarchy. Wait, don’t run away. We can do this. Let’s take a closer look at these scary words.
So What is a Template Hierarchy?
A template is nothing more than a pattern. There are many pages on your blog that have the same pattern – most blog posts, for example, will look much like this one – a picture, text, a side bar with stuff in it. There’s no need to invent the wheel over and over again, so WordPress uses template files for those pages. The cool thing about template files is that you can customise them for specific uses – if you have multiple authors, for example, you can give the big honcho a fancier bio page than the others, just by calling a different template file for that particular page.
A hierarchy is just a bunch of objects organised in a tree shape – something at the top, and other things branching off from it. That’s all it is. It’s a convenient way of organising things that are related to one another, like author bio template pages, for example. The generic bio page would be at the top, and any specific pages that are derived from it but have more stuff on them would branch off, each with their own specific name that could be called if they are needed.
A WordPress Theme is Created by Calling the Right File at the Right Time
WordPress themes are built on specific template files. Your theme gives structure to your blog in a dynamic fashion – when your reader clicks on a specific link, the appropriate template files are called in real time. It’s a combination of PHP calls (the server-side scripting language that allows your site appearance to change in front of the reader’s eyes) and the HTML coding that creates the actual pages that are called. The HTML is accompanied by a CSS file that contains all the styles used to make your pages look pretty and professional. At a minimum, a theme must have a style.css file and an index.php file to function. The style.css file houses the styles for your theme, as well as its name. The index.php file is the default template page for every section of a WordPress website. It’s possible to have an entire theme work from a single index.php template file, but WordPress frowns on that way of doing things, so we will use multiple files as required.
To become a real WordPress ninja like Chris or Jesse, one needs to have mastered PHP, HTML and CSS. We are going to learn a little bit of what we need from each one. If you want to know more, you’ll have to go deeper on your own. The book assumes that the reader already knows HTML and CSS. I do, but I’m not going to assume that you do – on the other hand I don’t want to bore people who already have that knowledge to tears. I’ll try to strike a happy medium, and please do scream in the comments if I’m going too fast or too slowly.
I think I’ve probably given most people enough to digest for one post, so I’m going to stop now. In the next post, we will take a closer look at the most common template files for blogs and then start building our own (very simple) theme! Stay tuned.