How to Display Subcategories on Category Pages in WordPress
WordPress usually displays primary categories in the sidebars or widget areas.
To enhance user engagement and site organization, it is possible to display subcategories on category pages in WordPress. It will provide users with a more intuitive and structured browsing experience.
Blog and e-commerce websites can benefit from displaying subcategories on category pages to better organize posts and display products.
This article will help you learn:
How to create categories and subcategories in WordPress and How to display subcategories on category pages in WordPress?
Why Display Subcategories on Category Pages in WordPress?
For user experience and effective presentation, content organization and navigation are crucial. To keep users engaged, it’s vital to present all content with a visual navigation map on the website. it helps to user visualize and find required content.
In case your website or blog has a lot of content, it’s advisable to group it into categories and sub-categories. By using categories and subcategories, website structure can be simplified, navigation can be improved, and users can easily find content.
It is possible to present categories and subcategories in sidebars, or subcategories on category pages.
How do I Organize Posts by Category in WordPress?
For better posts structuring, it is recommended to organize categories and subcategories in a hierarchy.
Take a look at the technology website as an example. There are categories such as gadgets and devices, software, and Innovative Tech.
Now, gadgets and devices may have subcategories such as smartphone reviews, mobile accessories, and app recommendations.
The software category encompasses new software and software reviews.
The category of innovative technology can have subcategories like futuristic gadgets, emerging technologies, conceptual designs, etc.
How do You Create a New Category in WordPress?
The process is very simple. Follow the steps.
Go to the WordPress left-side pan.
go to Post >> Categories.
Now write the name of the category in the field Name under the Add New Category section.
Now select the None in the field Parent Category, It will make it the main or top category.
You can also add a category Description.
How to Add Sub Category in WordPress
The process to add sub category in WordPress is very similar to adding a main category in WordPress. Follow the steps below.
To add sub categories go to Posts >> Categories.
Now write the name of the category in the field Name under the Add New Category section. Now select the category name in the field Parent Category, It will be the parent category of the newly made subcategory.
You can also add a category Description.
How to Display Categories and Subcategories in WordPress
To display categories on the website go to Appearance >> Widgets.
You can select Right Sidebar, Left Sidebar, Header or anywhere you want to display category and subcategory list.
Here we will display categories and subcategories on the Right Sidebar. Click on the +sign it will show an option in drop down.
Note: to learn about WordPress Widgets and How to Add Widgets to WordPress deeply read the article.
First, we will add a Heading to the category box.
Search for Heading then click Heading. Now type Heading.
It will add a Categories heading as shown below.
Now Click + sign again to add Categories and Subcategories to the Right sidebar.
Search categories in the search box. Click Categories List.
It will display the list of all categories and subcategories.
Organize Categories to Show on the Sidebar
You can select the options for how to display categories on the sidebar or any location. You have options Display as drop-down, Show post counts, Show only top level categories, Show empty categories, Show hierarchy.
Display Only Top Level Categories
Select the categories list as shown in the picture in the red box.
The settings option will appear in the right side panel.
Click the option Show only top level categories.
Display Subcategories Under Categories
In the settings option, in the right side panel.
Click the option Show hierarchy.
It will display show Categories and Subcategories in hierarchical order.
You can see Categories and Subcategories in the hierarchical order on the right sidebar as shown below.
How to Display Subcategories on Category Pages in WordPress
To display subcategories on the category page in WordPress you need to add code to the theme category.
Some themes don’t have a category page so you have to add a category page template. It is very easy. Follow the steps.
1 Create a category.php file in your theme. Now copy the code from the index.php and paste it to the category.php.
2. Insert the following code before the loop.
<?php
if (is_category())
{
$main_cat = get_query_var('cat');
if ($main_cat)
{
$current_category = get_category( $main_cat );
echo '<h1>'. $current_category->name .'</h1>';
$cats_list = wp_list_categories('echo=false&child_of=' . $main_cat . '&depth=1&title_li=&&show_count=1&hide_empty=0');
echo '<ul>' . $cats_list . '</ul>';
echo '<br />';
}
}
?>
For more category display options you can visit WordPress Developer Resources
Now it will display on the category page as shown below.
This page shows the category Gadgets And Devices and subcategories on the page.
Conclusion
In this article, we have explained the reasons, why displaying subcategories on category pages. By taking a thoughtful and user-centered approach, website visitors can benefit from better content discoverability and a more structured navigation.
Better hierarchical order helps improve SEO and attract more traffic. Proper navigation and display of content can be achieved by organizing it into categories and subcategories.
This article is intended to assist you in learning how to display subcategories on category pages in WordPress. In addition, it aids in the creation of sub-categories in WordPress, their organization, display, and editing.