Return to Snippet

Revision: 64720
at September 12, 2013 01:44 by lromak


Initial Code
//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');
 $count = count($terms);
 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');
 $count = count($terms);
 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>";
	 }?>

Initial URL


Initial Description
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.

Initial Title
List current post taxonomies and terms

Initial Tags
wordpress

Initial Language
PHP