Do you want to use different category templates on your WordPress website? WordPress allows you to use different templates throughout your website, which can be used for different categories. In fact, this is how many custom themes are created in the first place. Sadly this feature is not easy to use and will require you to edit files on the backend of your website.
Using different templates for your categories makes each one feel unique to your visitors and shows just how creative your website is. Keep in mind that using category templates is different from styling your categories. Today, I will demonstrate how to add and use category templates in WordPress.
What Are and Why Should You Use Category Templates
A category template allows for unique features and designs to be active for a single category, while other categories may use different templates. For example, if you have a dogs category, you may have a template that focuses on dog specific items like bones, paw prints, and dogs themselves.
Using category templates can really help your website stand out from the thousands of competitors you will face. It makes each category look meaningful and helps each piece of content stand out from one another. Being unique goes a long way when your website is one in a million. Every design choice matters and needs to be carefully made and be meaningful.
How to Add and Use Category Templates in WordPress
Today, I will demonstrate how to add and use category templates in WordPress. Before you begin this tutorial, you must take the time to create categories and add content to them. Adding category templates to WordPress requires you to edit files in the backend of your website. WordPress uses a hierarchy system to determine what template to load. By default, WordPress will use the theme’s templates, but by adding custom templates, WordPress will load and use those first.
This process may be slightly different depending on the theme you are using. You should also consider creating a backup of your website before beginning. This will ensure that you can fix your website if something goes wrong.
Finding Out the Current Hierarchy
You must first determine what your theme is loading. If you have never used custom templates before most likely your theme is reading the category.php file. If this is absent then the archive.php file will contain the information, but if this is also missing then the index.php file will be used. The key is to add a file that will be read before these.
For reference, here is what the template hierarchy system looks like in WordPress.
The files are read from 1 to 5 and if a file is not found it will move down.
Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.
You need to locate your current theme’s folder because the files you need will be located within it. Click on the public_html directory, then click on the wp-content folder. Inside of this folder, you will find all of the content related to your website. Click on the themes folder and enter the folder of the theme you are currently using.
Inside of this folder, you will see important files like the functions.php file, which is one of the most edited files in WordPress. Look through all of the folders and look for the categories.php, archives.php, and index.php files. In my case, I only had the archives.php and index.php files.Since archives.php is currently the highest ranked file, according to the hierarchy system, it will be read first, so I must introduce a file above that.
Adding a Category Template
Now that you know the current hierarchy you are ready to add a template. Alternatively, you could just add a category-slug.php file since it is always the first in the hierarchy. Make sure you name the file appropriately, for example, a category of “Dogs” with a slug of “dogs”, means that it will be named category-dogs.php. Make sure to confirm that your slug name is correct, or set one up if you have not already.
We need to add a new file by clicking on the “+ File” button.
A pop-up window will appear. Name the file appropriately and click on the “Create New File” button. If you do not name it correctly or misspell something, it will not work.
Your file in now created, but it is empty. Here is an example of a category-slug template file. This is only an example and must be edited to work correctly for your website:
Once you have set up your category template file, click on the “Save Changes” button to finish.
Congratulations, your website will now load the category template whenever a piece of content is under your specified tag. You can add multiple templates, but make sure they are unique enough to make it worth your time.
Fully Customize Your Website
Customizing your website is very important and helps your website stand out from the competition. Customization can range from category templates all the way down to the color of your theme. How your website looks is almost as important as how your website runs. Many visitors will not try a website if it does not look good.
How many category templates have you created? How unique are your templates from each other?
Author: Ron Helms
I currently work for GreenGeeks as a Support Technician. My primary roles are supporting our VPS and Dedicated server clients, as well as performing site migrations. With experience in the web hosting industry since 2009, there is rarely a question I can’t help answer. In my spare time, I enjoy gaming and working on cars as an automotive enthusiast.