Created
December 10, 2013 21:58
-
-
Save emaildano/7900991 to your computer and use it in GitHub Desktop.
Get Wordpress terms array with singular or plural term title functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get terms for post | |
// define category slug and name | |
$category = 'journals'; // Taxonomy Name | |
$categoryName = 'Journals'; // Front-end / Plural Name | |
$categorySingle = 'Journal'; // Front-end Singular Name | |
// end definition | |
$terms = get_the_terms( $post->ID , $category ); | |
$count = count($terms); | |
if ( $terms && ! is_wp_error( $terms ) ) : | |
if ( $count < 2 ){ | |
echo "<h4>$categorySingle</h4>"; | |
} elseif ( $count > 1 ) { | |
echo "<h4>$categoryName</h4>"; | |
} | |
echo '<small><ul>'; | |
foreach( $terms as $term ) { | |
$term_link = get_term_link( $term, $category ); | |
echo '<li><a href="' . $term_link . '" class="meta" data-toggle="tooltip" data-original-title="' . $categorySingle . '">'; | |
print $term->name; | |
echo '</a></li>'; | |
unset($term); | |
} | |
echo '</ul></small>'; | |
endif | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment