Get a list of registered taxonomy

Get a list of registered taxonomy without link

 <?php
              	$terms = get_terms( 'features' );
				 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
					 echo '<ul>';
					 foreach ( $terms as $term ) {
					   echo '<li>' . $term->name . '</li>';
						
					 }
					 echo '</ul>';
				 }
			   ?>

Get a list of registered taxonomy with link

<?php
					$args = array( 'hide_empty' => 0 );
					$terms = get_terms( 'features', $args );
					if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
						$count = count( $terms );
						$i = 0;
						$term_list = '<p class="features-archive">';
						foreach ( $terms as $term ) {
							$i++;
							$term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
							if ( $count != $i ) {
								$term_list .= ' , ';
							}
							else {
								$term_list .= '</p>';
							}
					}
					echo $term_list;
				}
				?>

Get a list of registered taxonomy By ID in single post page

<?php 
				  foreach((get_the_terms($post->ID, 'html-tag')) as $term)
						 {
							$term_link = get_term_link( $term );
   							// If there was an error, continue to the next term.
    							if ( is_wp_error( $term_link ) ) {
        							continue;
    							}
							echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>, ','';
						}
                  ?>
Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: