How Can I Create a Categories and Sub-categories Menu in WordPress?
I’ve seen this question asked a lot on the WP Forums and WP Stack Exchange along with several different answers. It really comes down to what you need. So, we’ll go over how to create a categories and sub-categories menu in two different ways and the pros/cons of each in this part of the tutorial.
First, before we get into this, did you know that a WordPress categories menu can be created without code and will also be editable on the dashboard? WpTavern tells you how!
Still interested in trying the PHP way? Awesome, let’s move on.
The big question: Does category.php apply to the children of the targeted category?
The answer: No. So now what?
For those not familiar with the power of category.php within a theme, you can catch up here. In a nutshell, you can apply a custom template to a specific category just by naming the template file with a convention that gets automatically picked up by WordPress. It’s a really awesome feature to take advantage of, but there’s one problem.
Category.php will not apply to the category’s children/sub-categories. So then, how do we apply a template to sub-categories? After lurking around online to find forum threads like this, and brainstorming with a co-worker of mine, I found some solutions to the problem and wanted to share them.
Before we begin:
You should have some knowledge as to how category.php works in a theme