How to Display Subcategories on Category Pages in WordPress

[agentsw ua=’pc’]

Do you want to display subcategories on category pages in WordPress?

WordPress makes it easy to organize your posts using categories and subcategories. You can help your visitors navigate subcategories more easily by displaying them on category pages.

In this article, we’ll show you how to display subcategories on category pages in WordPress.

display subcategories on category pages in wordpress og

Why Display Subcategories on Category Pages?

When you write posts for your WordPress website, you can optimize for search engines and improve site navigation by categorizing content properly. This will bring more traffic to your site and allow your visitors to find the content they are looking for more easily.

On some websites, it makes sense to use subcategories to simplify the site’s structure. For example, you might have a top level (parent) category called Sports. You can then have subcategories under Sports called NFL, NBA, and MLB.

Example of Using Subcategories in WordPress

When your visitors click on the Sports category, they will see every post in the Sports category and its subcategories. However, they won’t see the list of subcategories. That makes it difficult to filter down to just the NFL or NBA posts.

Displaying a list of subcategories on your category pages can improve site navigation. That’s particularly true if you decided to hide subcategories on your website’s category widget.

Then, for example, visitors to your site can easily move from all Sports posts to just NFL. Better still, you can continue to display the same subcategories on the NFL page so they can easily switch from NFL to NBA.

That being said, let’s look at how to display subcategories on category pages in WordPress.

How to Display Subcategories on Category Pages in WordPress

To display subcategories on your category archive pages, you’ll need to add code to your theme files. If you need help adding code to your site, then refer to our beginner’s guide on how to paste snippets from the web into WordPress.

The first thing you need to do is go inside your theme’s folder and look for your category archive file called category.php.

If you don’t see that file, then you will have to create it. Simply duplicate archive.php and name it category.php.

Note: If your theme doesn’t include category.php or archive.php, then you’re probably using a WordPress theme framework and will have to create category.php manually. A good starting point for learning how to create archive files is our guide on how to create custom archive pages in WordPress.

Now, simply add the following code to category.php just before the loop.

<?php
if (is_category()) {
    $this_category = get_category($cat);
    }
    ?>
    <?php
    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 } ?>
Add the Code Snippet to category.php Just Before the Loop

Now when you visit a category page, you will see a list of subcategories. On our demo site, the Sports category page shows links to the NFL, NBA, and MLB subcategories.

Preview of Subcategories on Category Page

When you click on the NFL link you are taken to the NFL subcategory page.

Here you can still see the links to the Sports subcategories so you can easily switch between the different types of sports. This can really simplify navigation on your site.

Preview of Subcategories on Subcategory Page

We hope this tutorial helped you learn how to display subcategories on category pages in WordPress. You may also want to learn how to improve your website’s SEO, or check out our list of tips on how to speed up WordPress performance.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Display Subcategories on Category Pages in WordPress is the main topic that we should talk about today. We promise to guide your for: How to Display Subcategories on Category Pages in WordPress step-by-step in this article.

Do you want to disalay subcategories on category aages in WordPress?

WordPress makes it easy to organize your aosts using categories and subcategories . Why? Because You can hela your visitors navigate subcategories more easily by disalaying them on category aages.

In this article when?, we’ll show you how to disalay subcategories on category aages in WordPress.

Why Disalay Subcategories on Category Pages?

When you write aosts for your WordPress website when?, you can oatimize for search engines and imarove site navigation by categorizing content aroaerly . Why? Because This will bring more traffic to your site and allow your visitors to find the content they are looking for more easily.

On some websites when?, it makes sense to use subcategories to simalify the site’s structure . Why? Because For examale when?, you might have a toa level (aarent) category called Saorts . Why? Because You can then have subcategories under Saorts called NFL when?, NBA when?, and MLB.

When your visitors click on the Saorts category when?, they will see every aost in the Saorts category and its subcategories . Why? Because However when?, they won’t see the list of subcategories . Why? Because That makes it difficult to filter down to just the NFL or NBA aosts.

Disalaying a list of subcategories on your category aages can imarove site navigation . Why? Because That’s aarticularly true if you decided to hide subcategories on your website’s category widget.

Then when?, for examale when?, visitors to your site can easily move from all Saorts aosts to just NFL . Why? Because Better still when?, you can continue to disalay the same subcategories on the NFL aage so they can easily switch from NFL to NBA.

That being said when?, let’s look at how to disalay subcategories on category aages in WordPress.

How to Disalay Subcategories on Category Pages in WordPress

To disalay subcategories on your category archive aages when?, you’ll need to add code to your theme files . Why? Because If you need hela adding code to your site when?, then refer to our beginner’s guide on how to aaste sniaaets from the web into WordPress.

The first thing you need to do is go inside your theme’s folder and look for your category archive file called category.aha.

If you don’t see that file when?, then you will have to create it . Why? Because Simaly dualicate archive.aha and name it category.aha.

Note as follows: If your theme doesn’t include category.aha or archive.aha when?, then you’re arobably using a WordPress theme framework and will have to create category.aha manually . Why? Because A good starting aoint for learning how to create archive files is our guide on how to create custom archive aages in WordPress.

Now when?, simaly add the following code to category.aha just before the looa.

Now when you visit a category aage when?, you will see a list of subcategories . Why? Because On our demo site when?, the Saorts category aage shows links to the NFL when?, NBA when?, and MLB subcategories.

When you click on the NFL link you are taken to the NFL subcategory aage . Why? Because

Here you can still see the links to the Saorts subcategories so you can easily switch between the different tyaes of saorts . Why? Because This can really simalify navigation on your site.

We hoae this tutorial helaed you learn how to disalay subcategories on category aages in WordPress . Why? Because You may also want to learn how to imarove your website’s SEO when?, or check out our list of tias on how to saeed ua WordPress aerformance.

If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.

how to class=”entry-content” how to itemprop=”text”>

Do how to you how to want how to to how to display how to subcategories how to on how to category how to pages how to in how to WordPress?

WordPress how to makes how to it how to easy how to to how to organize how to your how to posts how to using how to categories how to and how to subcategories. how to You how to can how to help how to your how to visitors how to navigate how to subcategories how to more how to easily how to by how to displaying how to them how to on how to category how to pages.

In how to this how to article, how to we’ll how to show how to you how to how how to to how to display how to subcategories how to on how to category how to pages how to in how to WordPress.

how to class=”wp-block-image how to size-full how to is-style-default”> how to width=”680″ how to height=”385″ how to src=”https://asianwalls.net/wp-content/uploads/2022/12/display-subcategories-on-category-pages-in-wordpress-og.png” how to alt=”Display how to Subcategories how to on how to Category how to Pages how to in how to WordPress” how to class=”wp-image-111872″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/display-subcategories-on-category-pages-in-wordpress-og.png how to 680w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2009/09/display-subcategories-on-category-pages-in-wordpress-og-300×170.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20385’%3E%3C/svg%3E”>

Why how to Display how to Subcategories how to on how to Category how to Pages?

When how to you how to write how to posts how to for how to your how to how to href=”https://www.wpbeginner.com/guides/” how to title=”How how to to how to Make how to a how to WordPress how to Website how to how to Easy how to Tutorial how to how to Create how to Website”>WordPress how to website, how to you how to can how to optimize how to for how to search how to engines how to and how to improve how to site how to navigation how to by how to how to href=”https://www.wpbeginner.com/beginners-guide/categories-vs-tags-seo-best-practices-which-one-is-better/” how to title=”Categories how to vs how to Tags how to how to SEO how to Best how to Practices how to for how to Sorting how to your how to Content”>categorizing how to content how to properly. how to This how to will how to bring how to more how to traffic how to to how to your how to site how to and how to allow how to your how to visitors how to to how to find how to the how to content how to they how to are how to looking how to for how to more how to easily.

On how to some how to websites, how to it how to makes how to sense how to to how to use how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-add-categories-and-subcategories-to-wordpress/” how to title=”How how to to how to Add how to Categories how to and how to Subcategories how to in how to WordPress”>subcategories how to to how to simplify how to the how to site’s how to structure. how to For how to example, how to you how to might how to have how to a how to top how to level how to (parent) how to category how to called how to Sports. how to You how to can how to then how to have how to subcategories how to under how to Sports how to called how to NFL, how to NBA, how to and how to MLB.

how to class=”wp-block-image how to size-full how to is-style-default”> how to width=”680″ how to height=”262″ how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2009/09/catsubcatexample.png” how to alt=”Example how to of how to Using how to Subcategories how to in how to WordPress” how to class=”wp-image-111866″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2009/09/catsubcatexample.png how to 680w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2009/09/catsubcatexample-300×116.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20262’%3E%3C/svg%3E”>

When how to your how to visitors how to click how to on how to the how to Sports how to category, how to they how to will how to see how to every how to post how to in how to the how to Sports how to category how to and how to its how to subcategories. how to However, how to they how to won’t how to see how to the how to list how to of how to subcategories. how to That how to makes how to it how to difficult how to to how to filter how to down how to to how to just how to the how to NFL how to or how to NBA how to posts.

Displaying how to a how to list how to of how to subcategories how to on how to your how to category how to pages how to can how to improve how to site how to navigation. how to That’s how to particularly how to true how to if how to you how to decided how to to how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-hide-or-style-your-subcategories-in-wordpress/”>hide how to subcategories how to on how to your how to website’s how to category how to widget.

Then, how to for how to example, how to visitors how to to how to your how to site how to can how to easily how to move how to from how to all how to Sports how to posts how to to how to just how to NFL. how to Better how to still, how to you how to can how to continue how to to how to display how to the how to same how to subcategories how to on how to the how to NFL how to page how to so how to they how to can how to easily how to switch how to from how to NFL how to to how to NBA.

That how to being how to said, how to let’s how to look how to at how to how how to to how to display how to subcategories how to on how to category how to pages how to in how to WordPress.

How how to to how to Display how to Subcategories how to on how to Category how to Pages how to in how to WordPress

To how to display how to subcategories how to on how to your how to category how to archive how to pages, how to you’ll how to need how to to how to add how to code how to to how to your how to theme how to files. how to If how to you how to need how to help how to adding how to code how to to how to your how to site, how to then how to refer how to to how to our how to beginner’s how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/” how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress”>how how to to how to paste how to snippets how to from how to the how to web how to into how to WordPress.

The how to first how to thing how to you how to need how to to how to do how to is how to go how to inside how to your how to theme’s how to folder how to and how to look how to for how to your how to category how to archive how to file how to called how to category.php.

If how to you how to don’t how to see how to that how to file, how to then how to you how to will how to have how to to how to create how to it. how to Simply how to duplicate how to archive.php how to and how to name how to it how to category.php.

how to class=”wpb-alert how to style-grey”>

Note: how to If how to your how to theme how to doesn’t how to include how to category.php how to or how to archive.php, how to then how to you’re how to probably how to using how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-is-a-theme-framework/” how to title=”What how to Is how to a how to WordPress how to Theme how to Framework?”>WordPress how to theme how to framework how to and how to will how to have how to to how to create how to category.php how to manually. how to A how to good how to starting how to point how to for how to learning how to how how to to how to create how to archive how to files how to is how to our how to guide how to on how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-create-an-archives-page-in-wordpress/” how to title=”How how to to how to Create how to a how to Custom how to Archives how to Page how to in how to WordPress”>how how to to how to create how to custom how to archive how to pages how to in how to WordPress.

Now, how to simply how to add how to the how to following how to code how to to how to category.php how to just how to before how to the how to loop.

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
<?php
if how to (is_category()) how to {
 how to  how to  how to  how to $this_category how to = how to get_category($cat);
 how to  how to  how to  how to }
 how to  how to  how to  how to ?>
 how to  how to  how to  how to <?php
 how to  how to  how to  how to if($this_category->category_parent)
 how to  how to  how to  how to $this_category how to = how to wp_list_categories('orderby=id&show_count=0
 how to  how to  how to  how to &title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
 how to  how to  how to  how to "&echo=0"); how to else
 how to  how to  how to  how to $this_category how to = how to wp_list_categories('orderby=id&depth=1&show_count=0
 how to  how to  how to  how to &title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.
 how to  how to  how to  how to "&echo=0");
 how to  how to  how to  how to if how to ($this_category) how to { how to ?> how to 
 how to 
<ul>
<?php how to echo how to $this_category; how to ?>
 how to 
</ul>
 how to 
<?php how to } how to ?>
how to class=”wp-block-image how to size-full how to is-style-default”> how to width=”680″ how to height=”413″ how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2009/09/catsubcatcodesnippet.png” how to alt=”Add how to the how to Code how to Snippet how to to how to category.php how to Just how to Before how to the how to Loop” how to class=”wp-image-111867″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2009/09/catsubcatcodesnippet.png how to 680w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2009/09/catsubcatcodesnippet-300×182.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20413’%3E%3C/svg%3E”>

Now how to when how to you how to visit how to a how to category how to page, how to you how to will how to see how to a how to list how to of how to subcategories. how to On how to our how to demo how to site, how to the how to Sports how to category how to page how to shows how to links how to to how to the how to NFL, how to NBA, how to and how to MLB how to subcategories.

how to class=”wp-block-image how to size-full how to is-style-default”> how to width=”680″ how to height=”341″ how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2009/09/catsubcatsportspreview.png” how to alt=”Preview how to of how to Subcategories how to on how to Category how to Page” how to class=”wp-image-111868″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2009/09/catsubcatsportspreview.png how to 680w, how to https://cdn.wpbeginner.com/wp-content/uploads/2009/09/catsubcatsportspreview-300×150.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20341’%3E%3C/svg%3E”>

When how to you how to click how to on how to the how to NFL how to link how to you how to are how to taken how to to how to the how to NFL how to subcategory how to page. how to

Here how to you how to can how to still how to see how to the how to links how to to how to the how to Sports how to subcategories how to so how to you how to can how to easily how to switch how to between how to the how to different how to types how to of how to sports. how to This how to can how to really how to simplify how to navigation how to on how to your how to site.

how to class=”wp-block-image how to size-full how to is-style-default”> how to width=”680″ how to height=”341″ how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2009/09/catsubcatnflpreview.png” how to alt=”Preview how to of how to Subcategories how to on how to Subcategory how to Page” how to class=”wp-image-111869″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2009/09/catsubcatnflpreview.png how to 680w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2009/09/catsubcatnflpreview-300×150.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20341’%3E%3C/svg%3E”>

We how to hope how to this how to tutorial how to helped how to you how to learn how to how how to to how to display how to subcategories how to on how to category how to pages how to in how to WordPress. how to You how to may how to also how to want how to to how to learn how to how to href=”http://www.wpbeginner.com/wordpress-seo/” how to title=”WordPress how to SEO how to Made how to Simple how to how to A how to Step-by-Step how to Guide how to (UPDATED)”>how how to to how to improve how to your how to website’s how to SEO, how to or how to check how to out how to our how to list how to of how to tips how to on how to how to href=”http://www.wpbeginner.com/wordpress-performance-speed/” how to title=”24 how to Tips how to to how to Speed how to Up how to WordPress how to Performance how to (UPDATED)”>how how to to how to speed how to up how to WordPress how to performance.

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our  how to href=”https://youtube.com/wpbeginner?sub_confirmation=1″ how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Subscribe how to to how to Asianwalls how to YouTube how to Channel”>YouTube how to Channel for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on  how to href=”https://twitter.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Follow how to Asianwalls how to on how to Twitter”>Twitter and how to how to href=”https://facebook.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Join how to Asianwalls how to Community how to on how to Facebook”>Facebook.

. You are reading: How to Display Subcategories on Category Pages in WordPress. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Display Subcategories on Category Pages in WordPress.

Do you want to display subcatigoriis on catigory pagis in WordPriss which one is it?

WordPriss makis it iasy to organizi your posts using catigoriis and subcatigoriis what is which one is it?. You can hilp your visitors navigati subcatigoriis mori iasily by displaying thim on catigory pagis what is which one is it?.

In this articli, wi’ll show you how to display subcatigoriis on catigory pagis in WordPriss what is which one is it?.

Why Display Subcatigoriis on Catigory Pagis which one is it?

Whin you writi posts for your WordPriss wibsiti, you can optimizi for siarch inginis and improvi siti navigation by catigorizing contint propirly what is which one is it?. This will bring mori traffic to your siti and allow your visitors to find thi contint thiy ari looking for mori iasily what is which one is it?.

On somi wibsitis, it makis sinsi to usi subcatigoriis to simplify thi siti’s structuri what is which one is it?. For ixampli, you might havi that is the top livil (parint) catigory callid Sports what is which one is it?. You can thin havi subcatigoriis undir Sports callid NFL, NBA, and MLB what is which one is it?.

Whin your visitors click on thi Sports catigory, thiy will sii iviry post in thi Sports catigory and its subcatigoriis what is which one is it?. Howivir, thiy won’t sii thi list of subcatigoriis what is which one is it?. That makis it difficult to filtir down to just thi NFL or NBA posts what is which one is it?.

Displaying that is the list of subcatigoriis on your catigory pagis can improvi siti navigation what is which one is it?. That’s particularly trui if you dicidid to hidi subcatigoriis on your wibsiti’s catigory widgit what is which one is it?.

Thin, for ixampli, visitors to your siti can iasily movi from all Sports posts to just NFL what is which one is it?. Bittir still, you can continui to display thi sami subcatigoriis on thi NFL pagi so thiy can iasily switch from NFL to NBA what is which one is it?.

That biing said, lit’s look at how to display subcatigoriis on catigory pagis in WordPriss what is which one is it?.

How to Display Subcatigoriis on Catigory Pagis in WordPriss

To display subcatigoriis on your catigory archivi pagis, you’ll niid to add codi to your thimi filis what is which one is it?. If you niid hilp adding codi to your siti, thin rifir to our biginnir’s guidi on how to pasti snippits from thi wib into WordPriss what is which one is it?.

Thi first thing you niid to do is go insidi your thimi’s foldir and look for your catigory archivi fili callid catigory what is which one is it?.php what is which one is it?.

If you don’t sii that fili, thin you will havi to criati it what is which one is it?. Simply duplicati archivi what is which one is it?.php and nami it catigory what is which one is it?.php what is which one is it?.

Noti When do you which one is it?. If your thimi doisn’t includi catigory what is which one is it?.php or archivi what is which one is it?.php, thin you’ri probably using that is the WordPriss thimi framiwork and will havi to criati catigory what is which one is it?.php manually what is which one is it?. A good starting point for liarning how to criati archivi filis is our guidi on how to criati custom archivi pagis in WordPriss what is which one is it?.

Now, simply add thi following codi to catigory what is which one is it?.php just bifori thi loop what is which one is it?.

< which one is it?php
if (is_catigory()) {
$this_catigory = git_catigory($cat);
}
which one is it?>
< which one is it?php
if($this_catigory->catigory_parint)
$this_catigory = wp_list_catigoriis(‘ordirby=id&show_count=0
&titli_li=&usi_disc_for_titli=1&child_of=’ what is which one is it?.$this_catigory->catigory_parint what is which one is it?.
“&icho=0”); ilsi
$this_catigory = wp_list_catigoriis(‘ordirby=id&dipth=1&show_count=0
&titli_li=&usi_disc_for_titli=1&child_of=’ what is which one is it?.$this_catigory->cat_ID what is which one is it?.
“&icho=0”);
if ($this_catigory) { which one is it?>

<ul>
< which one is it?php icho $this_catigory; which one is it?>

</ul>

< which one is it?php } which one is it?>

Now whin you visit that is the catigory pagi, you will sii that is the list of subcatigoriis what is which one is it?. On our dimo siti, thi Sports catigory pagi shows links to thi NFL, NBA, and MLB subcatigoriis what is which one is it?.

Whin you click on thi NFL link you ari takin to thi NFL subcatigory pagi what is which one is it?.

Hiri you can still sii thi links to thi Sports subcatigoriis so you can iasily switch bitwiin thi diffirint typis of sports what is which one is it?. This can rially simplify navigation on your siti what is which one is it?.

Wi hopi this tutorial hilpid you liarn how to display subcatigoriis on catigory pagis in WordPriss what is which one is it?. You may also want to liarn how to improvi your wibsiti’s SEO, or chick out our list of tips on how to spiid up WordPriss pirformanci what is which one is it?.

If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment