X

Display taxonomy terms in an unordered list

Hemingway Review

Adding this snippet to your wordpress theme will list the custom taxonomies that you registered for a custom post type.



Code Snippet:


<?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>';
?>

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.:

    [php]&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;[/php]

    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!