Created
June 15, 2019 07:09
-
-
Save thetwopct/7cbcb90045a00d59a79c6efd0756f5fd to your computer and use it in GitHub Desktop.
List all blog categories (with permalinks)
This file contains hidden or 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 | |
echo '<div class="post-categories">'; | |
$tax = 'category'; | |
$terms = get_the_terms($post->ID, $tax); | |
if (!empty($terms)) : | |
if (count($terms) === 1) { | |
echo "<p>Category:</p>"; | |
} else { | |
echo "<p>Categories:</p>"; | |
} | |
echo '<ul class="nostyle">'; | |
foreach ($terms as $term) { | |
echo '<li><a href="' . get_term_link($term->slug, $tax) . '">' . $term->name . '</a></li>'; | |
} | |
echo '</ul>'; | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment