Skip to content

Instantly share code, notes, and snippets.

@damianwajer
Created November 7, 2014 10:16
Show Gist options
  • Save damianwajer/24031a590525e0d41fba to your computer and use it in GitHub Desktop.
Save damianwajer/24031a590525e0d41fba to your computer and use it in GitHub Desktop.
[WordPress] Template to retrieve the terms in a taxonomy
<?php
/**
* Template to retrieve the terms in a taxonomy
* @link http://codex.wordpress.org/Function_Reference/get_terms
*/
$terms = get_terms( 'section' );
echo '<ul>';
foreach ( $terms as $term ) {
$term_url = get_term_link( $term, $term->taxonomy );
if ( function_exists( 'get_tax_meta' ) ) {
// function from Tax meta class for creating WordPress taxonomies custom fields
$term_image = get_tax_meta( $term->term_id, 'tax_image' );
}
if ( ! empty( $term_image ) ) {
$image = wp_get_attachment_image( $term_image['id'], 'thumbnail' );
} else {
$image = '<img src="placeholder.jpg" alt="placeholder">';
}
echo '<li>';
echo '<p>';
echo '<a href="' . esc_url( $term_url ) . '">' . $image . '</a>';
echo '</p>';
echo '<h3><a href="' . esc_url( $term_url ) . '">' . esc_html( $term->name ) . '</a></h3>'; ?>
<?php echo '<p>' . esc_html( nl2br( $term->description ) ) . '</p>';
echo '</li>';
}
echo '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment