Languages: English • 日本語 (Add your language)
Retrieve category list in either HTML list or custom format. Generally used for quick, delimited (eg: comma-separated) lists of categories, as part of a post's entry meta. For a more powerful, list-based function, see wp_list_categories().
<?php get_the_category_list( $separator, $parents, $post_id ); ?>
Categories are ordered by name regardless of the parent-child category relationship. See this example from wp_list_categories() to display the Post categories with the category relationship intact.
In content-single.php:
<?php /* translators: used between list items, there is a space after the comma */ $categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) ); /* translators: used between list items, there is a space after the comma */ $tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) ); if ( '' != $tag_list ) { $utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } elseif ( '' != $categories_list ) { $utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } else { $utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } printf( $utility_text, $categories_list, $tag_list, esc_url( get_permalink() ), the_title_attribute( 'echo=0' ), get_the_author(), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) ); ?>
By leaving the $separator value empty, it will generate an unordered list instead, complete with classes.
<?php echo get_the_category_list(); ?>
Result:
<ul class="post-categories"> <li> <a href="http://myblog.com/category/business" title="View all posts in Business" rel="category tag">Business</a> </li> </ul>
Since: 1.5.1
get_the_category_list() is located in wp-includes/category-template.php