Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Created June 15, 2019 07:09
Show Gist options
  • Save thetwopct/7cbcb90045a00d59a79c6efd0756f5fd to your computer and use it in GitHub Desktop.
Save thetwopct/7cbcb90045a00d59a79c6efd0756f5fd to your computer and use it in GitHub Desktop.
List all blog categories (with permalinks)
<?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