If you are familiar with WordPress, you will know how to use tags and categories to organize blog posts. While using custom post types in WordPress, you will have to organize them like categories and tags. Categories and tags can be described as taxonomies. WordPress permits you to create any number of custom taxonomies. Though these custom taxonomies work similar to categories or tags, they are in fact different. Here we learn how to create custom taxonomies.

How to Customize WordPress Archives For Categories And Tags

Using conditional tags

It is possible to add any custom template to achieve a unique view for any category or tag or custom taxonomy. All you need to do is to carry out a few simple changes. Never create too many templates as this will require you to adjust every template when you attempt to do some overall changes to the basic HTML markup you are using in every template in the theme. Unless you want a template that is drastically different from the theme’s archive.php, it is good to confine yourself to adding conditional changes to archive.php.

WordPress offers conditional functions to decide is a category or tag or taxonomy is displayed. To choose to show a category archive, use is_category() for categories, is_tag() for tags and is_tax() for custom taxonomies. You can also use the is_tag() and is_category() functions to test specific categories or tags by slug or ID. For custom taxonomies, you can use the is_tax() function can be used to find out if any taxonomy (excluding categories and tags), a particular taxonomy or a particular term in a taxonomy is displayed.

Creating Custom Taxonomies

You can add a custom taxonomy is any one of the three ways. For instance, you can code it manually following the instructions in the Codex (most experts do not recommend this). Secondly, you can generate the code with the help of GenerateWP. Thirdly, you can use a plugin to get custom content types like Pods or Types. In case of custom types, plugins enable you to create custom taxonomies and custom post types in WordPress backend. This process does not need you to write any code. This is perhaps the easiest way to add a custom taxonomy that will give you a framework to work with custom content types.

If you choose to follow any one of the first two options rather than using a plugin, you will need to add the code to a custom plugin or the theme’s functions.php file. It is good to create a custom plugin than to add the code to functions.php. Even when you are creating a plugin for the first time, this must be done. By adding the code to the theme’s functions.php, you can make it work. Nevertheless, when you switch themes while deploying a new theme or troubleshooting an issue, the taxonomy will cease to work.

While writing your custom taxonomy code as directed by the Codex or while generating it with GenerateWP, you just have to paste it in a text file and just add a single line of code before it. This will give you a plugin. You can upload it and install in the similar way you will do any other plugin.