Support » Fixing WordPress » Show the nearest category

  • I’ve been strolling around but I couldn’t find the answer.

    My post is in the following categories : Forest > Tree > Bark
    I would like to display <a href="linktobark">Bark</a> on single.php

    The code below shows me ‘Forest’

    	$category = get_the_category();
    	echo $category[0]->cat_name;

    Changing this to $category[3] displays ‘Bark’ as wanted, but what about posts in the ‘Tree’ section?

    Is there a way I can only show the youngest [?] category?

    Thanks for helping me out, guys.

  • The topic ‘Show the nearest category’ is closed to new replies.