Dissecting WordPress Themes: Recap and Preview

After a long summer hiatus, it’s a good time for a short recap of the prior articles in the series and a preview of the remaining parts.



  • In Part 1 we created a development environment and installed an IDE with which to develop PHP code. We introduced the WordPress theme and discussed its required components. We then created and activated a minimal trace theme that we use in the remaining parts of the series to explore the concepts of theme development. We walked through the creation of a few simple template files with trace messages.
  • Part 2 introduced the WordPress Loop by creating a simple while loop in index.php to display posts in the default reverse-chronological order. Several template tags were used to retrieve post information to include in the page output. We demonstrated how the Loop automatically adjusts its output based on whether a single post or multiple posts are requested. Some simple page navigation was added and we showed the impact of several WordPress settings on the Loop output.
  • In Part 3 we began our discussion of the WordPress Template Hierarchy by examining the Single-Post Hierarchy. In the Single-Post Hierarchy, single.php, if present in the theme directory, will override index.php when a single post is requested. This article also described the various Post Formats by enabling them in functions.php and adding a post format indicator to the index.php posts display table. We then used the get_template_part() function to dynamically call different template files based on the post format of each post. Finally, we took a look at Custom Post Types. We created a new type called my_book and merged posts of this type with normal posts in the index.php output. We were then able to use the single-post hierarchy to override single.php with single-[post type].php templates for selective formatting by custom post type.
  • Part 4 continued discussing the single-post hierarchy with attachment pages. This hierarchy has additional levels for all attachments, attachments for a particular MIME type/subtype, attachments with a subtype, and attachments with a particular MIME type. We also demonstrated how to load files into the Media Library and attach them to a post.
  • In Part 5 we began our study of the archive hierarchy with category archives. We assigned categories to our posts and custom post type instances and demonstrated how the default Loop filters objects by category when a specific category is queried. We demonstrated that archive.php will be executed when present in the theme folder whenever an archive of any type is requested. We further showed that special formatting can be achieved for category archives by creating a category.php template and that individual categories can be isolated by category ID or slug templates. A few category-related template tags, hierarchical categories, and category lists were also illustrated in the examples.
  • Continuing with the archive hierarchy Part 6 explored tag archives. In terms of the template hierarchy, tags work almost identically to categories. They are rooted with the archive.php template which can be overridden for just tag archives or for individual tags by either ID or slug. We found that the main difference between categories and tags is that tags do not have a parent/child relationship and thus cannot be arranged into a hierarchy. However, WordPress does provide a handy tag cloud, which we demonstrated at the end of the article.
  • Next up in the archive hierarchy discussion was the author archives in Part 7. In this article we created some authors and assigned them to our posts. We then demonstrated how the Loop can filter by author just as it did for categories and tags. Special formatting can be achieved for all author archives as well as individual authors (by either ID or name) using the template hierarchy. We wrapped up this article by showing how simple it is to generate a list of hyperlinked authors in the page footer.
  • Date archives are examined in Part 8. We added publication dates to the posts and displayed those using the index.php and archive.php templates. As with the other archives we found that the Loop automatically filters the posts when a particular date link is selected. For special formatting of date archives the date.php template can be used. We also showed examples of creating lists of publication months and years as you might see in the sidebar or footer of a blog site. Finally, a few conditional tags allowed us to customize the trace message depending upon the archive timeframe selected.
  • In addition to categories and tags, the taxonomies that ship with WordPress, you can create your own custom taxonomies. In Part 9 we showed how to create a custom taxonomy and assign its terms to existing posts and instances of our custom post type. We then added links for the terms and demonstrated that the Loop automatically filters posts by the selected term. Using the template hierarchy, special formatting for custom taxonomies can be achieved using the taxonomy.php template. Further specialization can be tailored to a particular taxonomy and even a particular term within a taxonomy using additional templates in the template hierarchy. We wrapped up this article with a demonstration of displaying a term cloud in the page footer.
  • To complete the coverage of the archive hierarchy, Part 10 explored Custom Post Type archives. We first created a link to our custom post type in the page header and found that our code that merged books with other posts needed to be tweaked so that it would not do the merge on the book archive page. This allowed the Loop to perform its default function of filtering just the custom post types requested. We then employed the template hierarchy to provide custom formatting for our custom post type.


Looking forward a bit, we’ll switch our focus from posts to pages. We’ll continue to flush out the template hierarchy for pages and page templates. We’ll also take a look at template hierarchy support for special-purpose pages such as home, front-page, search, 404, and comments popups. After pages, we’ll discuss some of the conditional tags that come into play when designing your own themes. Along the way, we’ll continue to incrementally build out our template hierarchy diagram.

More Ideas Than Time

Simultaneously with the template hierarchy discussion I will begin a new series that walks through some of the popular themes distributed by WordPress line-by-line. There’s no better way to learn how to develop themes than to inspect the work of other designers and engineers. I’ll also launch into a series that does a “deep dive” into the WordPress database and develops many queries that retrieve useful information that is not readily available from the Admin interface.

Speak Your Mind