I’m looking for a way to list all the terms from a custom taxonomy. Only the terms that have posts attached to it should have links to the archive page. If there are no posts attached it should only show the names.
Any ideas? Thanks!
<?php
$taxonomy = 'cat';
$queried_term = get_term_by( 'slug', get_query_var($taxonomy) );
$terms = get_terms($taxonomy);
if ( $terms !== 0 ) {
foreach ( $terms as $term ) {
echo $term->name . ", ";
}
}
if ( $terms > 0 ) {
foreach ( $terms as $term ) {
echo '<li><a href="' . $term->slug . '">' . $term->name .'</a></li>';
}
}
?>