OK, the idea is simple. Every wordpress site is uses categories and tags taxonomies by default in the following manner:
category taxonomy slug = wpsite.com/parent-cat-slug/sub-cat-slug/
tags taxonomy slug = wpsite.com/tag/tag-slug
In many cases, a category has a set of tags associated with posts within that category. If for some reason the author associates a post to multiple categories, then that same tag is carried along with it. I think we all understand that.
Here’s the problem, better demonstrated through an example:
Category 1 = politics
Category 2 = business
Tag = corruption
If I am under the “politics” category, reading a post tagged with corruption, and click on the tag link, it will take me to wpsite.com/tag/corruption and give me a list of posts that have that tag, all of which may or may NOT belong to the same category.
WHAT IF WE CAN DO THIS:
if you click on the tag “corruption” from inside the category “politics”, the permalinks would point to wpsite.com/politics/corruption only displaying post tagged with “corruption” from that category instead of a site wide list?
This method is used in the Guadian newspaper:
http://www.guardian.co.uk/culture (top category – hover your mouse over the “Latest video, audio and galleries” post links, each has the sub-taxonomy under the top gallery, and does NOT point guardian.co.uk/video or audio etc as demonstrated below)
http://www.guardian.co.uk/culture/video/2012/mar/24/vincent-van-gogh-house-london-sale-video
This is a great way of classifying and associating post formats or tags, in a human readable way, which is much better than the generic wpsite.com/tag/tag-slug structure.
So, is there a way for us to achieve this in wordpress?
Basically, yes, you can do that in WordPress. But there will be a whole lot works to achieve that.
To filter your category archive to show certain tags, simply you can go to
http://site.com/?category_name=politics&tag=corruption
, that would work. But what if we want to use permalink instead of that old query string kind of URL? Well, we can add new $wp_rewrite->rules for that.But it’s not just it, you will have to filter each
get_category_link()
andget_term_link()
functions to change your tags and category links to meet your needs. E.g, for tag links displayed on a category, we need them to point exactly to tag/category.Well, that’s the clue. As I said, it can be done.