WordPress Snippets at WPcustoms

Show current child category in template

This function displays the post’s current child category name.


/**
 * Snippet Name: Show current child category in template
 * Snippet URL: http://www.wpcustoms.net/snippets/show-current-child-category-in-template/
 */
 // usage in your template:

cat_name; ?>


// add this to your functions.php
function post_child_category( $id = null )
    {
        if ( $id = null )
            return false;

        $categories = get_the_category( $id );
        if ( count($categories) > 0 )
        {
            return $categories[count($categories)-1];
        } else {
            return false;
        }
    }