Display Taxonomy Terms in an Unordered List

Snippets by IsItWP

You may have registered taxonomies for a custom post type. These taxonomies can be displayed in an unordered list in WordPress template pages.

Instructions: Add the following code to a template file of your WordPress theme where you want to display taxonomy terms in unordered list.

			$terms = get_the_term_list( $post->ID, 'TAXONOMY_NAME',',',',','');
			$terms = explode(',',$terms);

			echo '<ul>';
				for($i = 0;$i<sizeof($terms);$i++){ ?>
					<li><? echo $terms[$i]; ?></li>
				<? }
			echo '</ul>';

You may also enjoy reading about custom taxonomy breadcrumb.

Comments   Leave a Reply

  1. Philippe Spicher January 4, 2019 at 5:59 pm

    thanks for the code – useful. Is there any way to display not only the terms, but the related images, in a grid?

  2. You can actually accomplish this with far less code. get_the_term_list() allows for before and afters and wraps to be set as parameters, so you could accomplish the same thing using one line of code, e.g.:

    &lt;?php echo get_the_term_list( $post-&gt;ID, 'TAXONOMY_NAME', '&lt;ul&gt;&lt;li&gt;','&lt;/li&gt;&lt;li&gt;','&lt;/li&gt;&lt;/ul&gt;'); ?&gt;
    1. you are right, good call Drew, Ill updated the post with the new version.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!