WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category parents

Contents

Description

Returns a list of the parents of a category, including the category, in hierarchical order.

Usage

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

Parameters

$id
(integer) (required) Category ID.
Default: None
$link
(boolean) (optional) Whether to create a link to each category displayed.
Default: false
$separator
(string) (optional) What to separate each category by.
Default: '/'
$nicename
(boolean) (optional) Whether to use nice name for display.
Default: false
$visited
(boolean) (optional) Already linked-to categories. This parameter is used internally by the function, which makes recursive calls to itself, to prevent duplicates in the returned list.
Default: array()

Return Values

(string|WP_Error) 
The categories, separated by $separator. WP_Error on failure.

Example

Returns the parent categories of the current category with links separated by '»'

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

will output:

Internet » Blogging » WordPress »

Change Log

Source File

get_category_parents() is located in wp-includes/category-template.php

Related

See also index of Function Reference and index of Template Tags.