I want to display the direct category ancestor of a given post. An illustrative example:
These are the categories I have:
- Cat1
- Cat2
- Cat2.1
- Cat2.1.1
- Cat2.1.2
- Cat2.2
- Cat2.2.1
- Cat2.2.2.
- Cat2.3
- Cat2.1
- Cat3
- Cat4
I only put the posts in a single category between a same "level", but when the category has more sub categories, I check the whole trailing, like in:
- Cat1
- [X] Cat2
- [X] Cat2.1
- Cat2.1.1
- [X] Cat2.1.2
- Cat2.2
- Cat2.2.1
- Cat2.2.2.
- Cat2.3
- [X] Cat2.1
- Cat3
- Cat4
Now, in the single post page, I want to display the name of the direct category ancestor of the post (Cat2.1.2 in this case). By default I just use get_the_category()
, but it shows the top level category instead (Cat2 in this case). I don't considerer unchecking top levels by now because it cause another problems within the template.