• I have created a new theme for an existing wordpress page. Inside the loop, it shows every post as kind of a teaser with a thumbnail image, the title below the image and the category name of the post, above the image.

    The problem I have is the correct way to show the category name. I want it to show the lowest hierarchy category name (e.g. if there’s a parent and a child category, I want the child category name to be displayed), and one category name only. Furthermore I want to exclude the category name “frontpage” from showing up.

    So the category structure of my site contains 13 main categories and 5 child categories. I have already tried $last_category = end($category) but it seems, that wordpress orders the categories alphabetically so that the last or end category isn’t necessarily the lowest in the hierarchy, but the last in the alphabet.

    For example in the parent category “Brand Planning” the code $last_category = end($category) works, because the child categories are named “content” and “press”. But in the parent category “events” it doesn’t, because the child category is named “arrangements”.
    In case of a displayed child category name, I want the link to be directing to the respective parent category.

    Long story short: Above every post I want one(!) category name to be displayed, which shouldbe the lowest hierarchical category name and in case of a child category name, should link to the respective parent category.

    Any suggestions? Thanks a lot in advance!

The topic ‘display lowest category name’ is closed to new replies.