WordPress – How to force sub categories to use PARENT category in WordPress


lightbulbAfter much digging around and trying to find a suitable plugin or PHP if/then statement, I came across a nice little site that did it for me using the functions.php page.

I would love to say I wrote this handy bit of code myself but I did not. Much praise to for the skilled coder at brassblogs.

Now, the way to use this is to take the code on this text file and add it to your functions file.

After you add that to your functions.php file, you simply need to make a template for EACH PARENT CATEGORY. The child categories will then use the template that their PARENT uses. YEA!

Category Template in WordPress

It’s very easy to make a category template. The simplest way is to take the existing archive.php file in your WordPress theme and save it as category-ID.php where the ID is the NUMBER of the category. You can check this by going into your wp-admin, clicking on the category and reading the complete URL for the ID= (it will be at the end of the string).

So, if your category is #1, you will make category-1.php. You can style this page in any way you want; you can change link colors, text colors or even make it look completely different from the rest of your WordPress blog – it’s completely up to you!

This will apply to all parent categories that you want to use a special template; simply find the category ID, create the page, name it category-XX.php (where XX is your category ID) and upload it to your theme folder. Or use the sample you can download here.

Again, credit goes to brassblogs.com! Thanks!

Author: Debbi

Owner & Online Business Expert @ Design - Market - Evolve

Leave a Reply

Your email address will not be published. Required fields are marked *