get_category_parents(): Get the Parent Category Path

get_category_parents Description

Returns the list of parent categories for a given category in hierarchical order, including the current category.

get_category_parents Usage

<?php get_category_parents( $id, $link, $separator, $nicename, $visited ); ?>

get_category_parents Parameters

$id

(integer) (required) Category ID
Default: None

$link

(boolean) (optional) Whether to add category links to the returned categories
Default: false

$separator

(string) (optional) Separator between categories
Default: '/'

$nicename

(boolean) (optional) Whether to display a friendly name
Default: false

$visited

(boolean) (optional) Categories that have already been linked. This argument is used internally to avoid duplicate items appearing in the returned list.
Default: array()

get_category_parents Return value

(string|WP_Error)

The parent category list for the specified category, separated by $separator. If the function fails, it returns WP_Error.

get_category_parents Example

Return the linked parent category path of the current category, separated by ».

<?php echo get_category_parents( $cat, true, ' » ' ); ?>

The code above outputs:

Internet » Blogging » WordPress »

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *