Skip to content

A Beginner’s Guide to WordPress Theme Development: Day 5

We’ve arrived! Today is the final day of the [bg] series on [wp]!
  • Day 1: Introduction, the fundamentals of WordPress theme development
  • Day 2: The index.php and style.css files: the most important parts of any theme.
  • Day 3: The header.php, sidebar.php and footer.php files.
  • Day 4: The single.php file: the file that handles posts.
  • Day 5: The archive.php, home.php and functions.php files and a wrap up of all that has gone on. You will also be able to download the whole series as an eBook.

download-5

We’re nearly there. This is the final day of ‘A Beginner’s Guide to WordPress Theme Development’. We’ve got three files to tackle today, but there isn’t too much I’m going to say on each of them. Let’s start with the archive.php file. Download the latest copy of our theme, Champion, unzip it and load up the archive.php file in your text editor.

Creating an awesome archive page in WordPress

day5

According to the WordPress file hierarchy (which we discussed on day two), all archives – date, category, author and tag each have their own template file, but they also all fall back on a single file – the archive.php file. The idea here is that if you’re clever, you can save yourself creating a couple of additional files. Upon opening the file, you’ll be greeted with the familiar get_header and the loop. Then, on line 14 starts a whole load of PHP if statements – if this is a category archive, display this, if this is a tag archive, display this etc etc. After that, on line 37 the loop swings into action and we have the familiar template tags we learnt on day two. Finally, on line 56 the standard “no posts were found” gets replaced with another if statement, changing it to “no posts were found under this category/tag etc etc”. After that, the familiar get_sidebar and get_footer and the archive page ends. It’s pretty similar to the index.php page, all that is happening is that there are a couple of if statements to change the titles according to the archive.

Creating an (equally awesome) homepage

Something you might have noticed is that so far we haven’t created a specific homepage. Whilst there is a homepage, that’s just the contents of the index.php file. At this point, it’d be appropriate to introduce a new template file: the home.php file. It’s highest in the hierarchy for the homepage, so WordPress first looks for the home.php file and if that doesn’t exist then it uses the index.php, which is why so far we’ve so far been creating a homepage with just the index.php.

Yay! 🎉 You made it to the end of the article!
Alex Denning
Share:

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
mamun
September 22, 2012 8:37 am

This is really good tutorial, structured, full, easy to understand.. I appreciate…. Thank YOu

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!