X

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.

		<?php
			$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. 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!