So I am attempting to build the first page in my navigation hierarchy to choose product categories.
I have a custom taxonomy called collections. I would like to create a page that loops through all terms in the collections taxonomy and displays the Term +link and description. Just about everything I have found besides the code below is creating a list of post from a particular taxonomy. That is not what I want yet. I want a master page that has each taxonomy term with a description that then links to the post that corresponds to that term.
For example if my taxonomy was transportation, terms may be car, boat, plane which would have a description explaining what a car boat or plane is. Then each term would link to a list of specific cars or whatnot.
I created a file called taxonomy-collections.php
and put the following code in. But it is not doing the trick, can anyone suggest a solution to this problem?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$terms = get_terms( 'collections' );
echo '<ul>';
foreach ( $terms as $term ) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
echo term_description($post->ID,$term);
}
echo '</ul>';
?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
This is almost straight from the codex, so I'm guessing I am missing something.
currently the code has each term displayed as a list, but I do want to change it to a grid format if someone could help with that too.
So each term and description will be wrapped in a div and right aligned with the next.