/ Published in: PHP
To be used in WordPress template. List full taxonomy, or only custom post type associated with the post. Examples include a linking or non linking list.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//To list FULL custom taxonomy <?php $taxonomy = 'replace_this_with_taxonomy_name'; $queried_term = get_query_var($taxonomy); $terms = get_terms($taxonomy, 'slug='.$queried_term); if ($terms) { echo '<ul>'; foreach($terms as $term) { echo '<li><a href="'.get_term_link($term->slug, $taxonomy).'">'.$term->name.'</a></li>'; } echo '</ul>'; } ?> //To list ONLY custom taxonomy associated with post: //non-linking, list only: <?php $terms = wp_get_post_terms($post->ID,'replace_this_with_taxonomy_name'); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug, 'replace_this_with_taxonomy_name').'">'. $term->name . "</a></li>"; } echo "</ul>"; }?> //links to taxonomy archive: <?php $terms = wp_get_post_terms($post->ID,'replace_this_with_taxonomy_name'); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug, 'replace_this_with_taxonomy_name').'">'. $term->name . "</a></li>"; } echo "</ul>"; }?>