WordPress.org

Codex

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

Function Reference/get the term list

Description

Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.

Usage

 <?php get_the_term_list$id$taxonomy$before$sep$after ?> 

Parameters

$id
(int) (required) Post ID
Default: None
$taxonomy
(string) (required) Name of taxonomy
Default: None
$before
(string) (optional) Leading text
Default: empty string
$sep
(string) (optional) String to separate tags
Default: empty string
$after
(string) (optional) Trailing text
Default: empty string

Returns

(string) 
HTML string of taxonomy terms.
(bool) 
false if the post does not have any associated terms.

A Basic Example

Used inside the loop this outputs the terms from the people taxonomy for a specific post.

<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' ); ?>

This would return something like.

People: <a href="person1">Person 1</a>, <a href="person2">Person 2</a>, ...

Returning an HTML List

Used inside the loop this outputs the terms from the styles taxonomy for a specific post as an (x)html list.

echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );

This would return something like.

<ul class="styles">
    <li><a href="person1">Style 1</a>,</li> 
    <li><a href="person2">Style 2</a></li>
</ul>

Change Log

Source File

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

Related

get_the_tag_list()

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