WordPress.org

Ready to get started?Download WordPress

Forums

Show the nearest category (1 post)

  1. Norke
    Member
    Posted 2 years ago #

    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'

    <?php
    	$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.

Topic Closed

This topic has been closed to new replies.

About this Topic