Inside the post-functions.php (framework>functions) I’m trying to write code to output parent category name with url link.
For example, post “I like sweet things” belongs to category “gummy” that has parent category “lollipop”. I want to be able to output “lollipop” with url going to lollipop (not direct category gummy but its parent).
My code is below and it seems very close, however this code outputs “gummy” for category name but url is of “lollipop”. The URL is correct but category name should output parents name (lollipop) too. By the way, when post category doesn’t have parent, this outputs category name and url both correctly.
The code is slightly modified and now I can see “lollipop” (parent cat name and url pointing that parent cat). But for other post which doesn’t have parent category lost category output.
For example when the post “I like sweet things” belongs to “gummy” that has no parent, there will be no cat name output (neither gummy nor its url pointing to gummy). As a result inside <span class=”category”> becomes empty.
I think this code above only works for the post that belongs to category which has parent.
*With the very first code http://pasted.co/b5f13504 works fine only for the post belongs to category which doesn’t have parent.