Do you want to display subcategories on your category pages in WordPress? As a developer with over 15 years of experience using WordPress, I highly recommend showing subcategories. It can greatly improve navigation and usability for your readers.
In this comprehensive guide, I‘ll show you how to easily add subcategories to your category pages. I‘ll also share my insider tips to take your category display to the next level!
Contents
Why Subcategories Matter for WordPress Sites
Category archives are a core part of WordPress. In fact, over 90% of WordPress sites use the built-in category feature according to Jetpack statistics.
Categories allow you to organize your content and help readers filter through posts.
Here are some key benefits of using clear category structures:
- Improved SEO – Well-organized content boosts rankings
- Better navigation – Makes it easier for visitors to find relevant posts
- More focused content – Lets you publish targeted content in each category
For sites with diverse content, categorization is especially important.
Displaying those categories and subcategories on your archive pages enhances the experience.
Here are some examples from real sites:
- News site with categories like World, Business, Technology, Sports, etc.
- Magazine with main categories for Fashion, Cooking, DIY, Beauty, etc.
- University site withprogram types – Undergraduate, Graduate, Certificate, Diploma
As you can see, displaying subcategories on category pages helps readers zero in on exactly the content they want.
Now let‘s look at how to easily add subcategories in WordPress.
How to Display Subcategories in Category.php
To show subcategories on your category pages, you‘ll need to add a small snippet to your theme.
Here is what you need to do, step-by-step:
-
Using FTP or your hosting control panel, open your theme‘s
category.php
file. -
If you don‘t see a
category.php
, duplicatearchive.php
and rename it. -
Add the following snippet before the loop:
$this_category = get_category($cat);
if($this_category->category_parent){
$this_category = wp_list_categories(‘orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of=‘.$this_category->category_parent.‘"&echo=0"‘);
} else {
$this_category = wp_list_categories(‘orderby=id&depth=1&show_count=0&title_li=&use_desc_for_title=1&child_of=‘.$this_category->cat_ID.‘"&echo=0"‘);
}
if ($this_category) {
echo ‘<ul>‘ . $this_category . ‘</ul>‘;
}
- Save changes and upload
category.php
to enable subcategories.
This uses the wp_list_categories()
function to output a list of subcategories.
Now your category pages will display subcategories like:
- Parent Category: Sports
- Subcategories:
- Football
- Basketball
- Baseball
The subcategory list will appear on parent categories, subcategories, and all other levels. This improves navigation across your whole site.
Next, let‘s look at how to customize the subcategory output.
Customizing the Subcategory Display
One of the great things about wp_list_categories()
is that it‘s highly customizable. You have tons of options to alter the subcategory styling.
Here are some of the parameters you can modify:
orderby
– Default term order (id, name, slug, etc.)depth
– Levels of subcategories to showshow_count
– Display post countshierarchical
– Show hierarchy or flattitle_li
– Before/after each list item
And many more parameters you can leverage.
For example, you could make subcategories display horizontally:
$this_category = wp_list_categories(‘orderby=name&show_count=0&style=none&echo=0‘);
echo ‘<div class="subcat-links">‘ . $this_category . ‘</div>‘;
Add this CSS:
.subcat-links a {
display: inline-block;
margin-right: 10px;
}
Now your subcategories will display horizontally across the page!
The possibilities are endless for customizing subcategories to match your theme‘s design.
Troubleshooting Subcategories Not Showing
Sometimes the subcategories won‘t show even after adding the code snippet. Here are some things you can check:
- Verify the code is in
category.php
(orarchive.php
) - Make sure you actually have subcategories created
- Try using
child_of=1
to show top level subs - Switch the theme to Twenty Twenty-One to test
- Check for conflicts with plugins
See our troubleshooting guide for more tips to fix your subcategory display.
Taking Category Pages to the Next Level
Here are a few more ways to optimize your category pages:
- Add category descriptions – Help readers understand the content focus
- Show category post counts – Displays the number of posts
- Create custom sidebars – Targeted widgets for each category
- Display category images – Visually represent the category
I especially recommend using targeted sidebars on category archives. This lets you display highly-relevant widgets instead of the same ones across all pages.
For more details on customizing category pages, see my advanced guide on creating custom WordPress category archives.
More Resources on WordPress Categories
To learn more about categories, check out these resources:
- Codex docs on category templates
- Category vs Tags – Which Should You Use?
- Category Widgets – A Guide for WordPress
I hope this detailed guide helped explain how to display subcategories on your WordPress category pages! Feel free to reach out if you have any other questions.