2025-03-24 02:41:04
Fortunately, WordPress has a category and subcategory structure that helps you organize content systematically.
Displaying subcategories on the main category page can make it easier for users to find the topics they want.
In this article, we will introduce how to display subcategories on the category page in WordPress, along with sample code and step-by-step instructions to improve your website's navigation.
Properly categorizing content not only makes your website look organized but also helps with SEO and enhances the user experience for visitors.
For example, if you have a main category called "Sports," you might have subcategories like "NFL," "NBA," and "MLB." When customers go to the "Sports" category page, they will see all posts related to sports, but they won't be able to conveniently browse only the NFL or NBA.
If you display a list of subcategories on the main category page, users can easily click on the topics they are interested in, making navigation on your website smoother.
You can display subcategories on the category page by adding code to your theme file. If you are not familiar with adding code in WordPress, please refer to our guide on how to add code in WordPress.
<?php
if (is_category()) {
$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) { ?>
<ul>
<?php echo $this_category; ?>
</ul>
<?php } ?>
After adding this code, save the file and go to the category page on your website. You will see the subcategory list displayed.
Displaying subcategories on the main category page in WordPress is a great way to make your website more user-friendly by using simple code. You can improve navigation and help users find the content they need more quickly.
2025-01-10 10:12:01
2024-05-31 03:06:49
2024-05-28 03:09:25
There are many other interesting articles, try selecting them from below.
2023-10-26 05:02:33
2023-10-30 04:53:34
2023-11-23 01:36:57
2023-11-07 11:39:12
2023-11-23 01:30:37
2023-11-23 10:27:28
2023-12-13 03:10:57
2024-05-08 03:52:01
2024-03-08 02:58:26