Press "Enter" to skip to content

Quick Tip: What is a WordPress Archive?

Whenever I’m talking WordPress to someone, I have a habit of using terminology that is specific to WordPress. Problem is, not everyone is familiar with said terminology, and sometimes I need that reminder. At the same time, I want those that I work with, to become comfortable with the WordPress “lingo” being used as it probably won’t be the last time they’ll encounter it. That is my inspiration for this newest quick tip. We’ll be diving into one of these words that I say often – the “archive”. What is a WordPress archive? How can we, as developers, benefit from it?

The literal definition vs the WordPress definition

First, let’s go over what this mysterious archive is. Here is the dictionary definition of an archive:

A repository or collection especially of information.

In WordPress, an archive is the same. It is a collection of information, or in this case, WordPress posts, based on a commonality.

That commonality can be several things, and there are several archive types in WordPress. Now what do I mean by commonalities? I mean that archives group together posts that have something in common.

The good news is, WordPress does most of this out of the box, with little effort on our part. Before we get into how WordPress does this, let’s go over some examples of commonalities or groupings of posts first.

Examples of Commonalities

For my first example, my new series of “Quick Tips” is based on a category. If I want to display my entire collection of posts with the category “Quick Tips” on the front-end, that page would be referred to as a category archive. I’m pasting the literal link below so you can also see the permalink structure:

https://rachievee.com/category/quick-tips/

Any category, whether it’s a parent or a child, will be referred to as a category archive. And just like the category archive, you can use archives with various other types of commonalities. I’ve included a list below based on my blog:

You can also have archives based on post type. I don’t have any custom post types on my blog as an example, but let’s imagine a WooCommerce store in WordPress. In the store, I want to display my  collection of products. These products are custom post types. The page that displays all of these products on the front-end, will be referred to as a custom post type archive.

Here is an example of a custom post type archive from a WooCommerce Demo I found: WooCommerce Demo: Blender Archive

This is an archive template for “Blenders”. If you inspect the HTML body classes, you will also see more evidence that it is an archive.

How does this benefit developers?

Knowing about some of the commonalities that WordPress considers an archive, can help developers determine how best to create templates for their themes. Whenever I’m in the planning stages of building a new WordPress theme or editing an existing one, I need to understand what content is involved and how it’ll be maintained.

By knowing this, combined with how the WordPress template hierarchy works, I can make an informed decision.

Not sure how the template hierarchy works yet? I briefly touch upon what this hierarchy is in another quick tip of mine, “Quick Tip: Not sure what template you’re in? Use the WordPress body classes“. Long story short, it’s a flowchart detailing how WordPress decides what template files to use in your WordPress theme, based on the type of content it is. WordPress also determines what template to use based on file name.

I can take advantage of WordPress’ archive templates once I understand the content type and commonality. By naming the template according to the content type (category, tag, date etc.), with a default WordPress loop, I can have a working template in two minutes. Yep, that’s fast!

If there are no other files in a WordPress theme aside from the required index.php, style.css, and functions.php, the archive.php template file will be used to display every type of archive on the front-end. That is the “first stop” WordPress makes when using a theme.

Now what if I want my author archive to look different than my category archive? That is when I start going down the WordPress hierarchy flowchart, and create more granular templates for WordPress to use instead. I’ve included a messy screenshot below of the WordPress template hierarchy with some notes. The screenshot shows how WordPress “makes stops” to choose templates for category archives as an example.

WordPress Template Hierarchy
Links to enlarged version.

Wrapping up

Before we end this quick tip, let’s quickly review what we went over. What is a WordPress Archive? In general, an archive is a collection of information. In WordPress, it’s a collection of posts based on what they have in common.

These commonalities can be many things, but some examples* I gave were:

  • Categories
  • Tags
  • Dates
  • Post Types

*Keep in mind that there are other archives that I didn’t mention. Author archives being one of them.

I also briefly mentioned the WordPress template hierarchy. As developers, by understanding the content we’re working with, and this hierarchy, we can determine if an archive template will be of use. If it is, we can also decide which template file based on the hierarchy, will best fit our needs.

Once we’ve made all of those decisions, by adding the default WordPress loop to a properly named file, we can have a functional archive template in minutes.

I hope this quick tip has been useful! If you have any ideas for more – let me know. Still confused about archives? Drop some questions in the comments. Happy WordPressing!

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.