Im using the taxonomy images plugin which allows me to assign images to categories … im not quite sure how to show it on the front end though.
My code that displays categories is as follows:
$cat = get_query_var('cat');
$args = array(
'orderby' => 'id',
'child_of' => $cat,
'hide_empty' => 0
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link( $category->term_id ) . '" class="cat-c-top-bg">' . "n";
echo ' <h4>' . $category->name . '</h4>' . "n";
echo ' <div class="icon-view">' . "n";
echo ' </div>' . "n";
echo ' <div>' . "n";
echo ' <img src="" width="164" height="164"></img>' . "n";
echo ' </div>' . "n";
echo ' <div class="cat-bot-ext_bg">' . "n";
echo ' </div>' . "n";
echo '</a>' . "n";
}
Which works PERFECT … although, whe i enter the code supplied by the image plugin, it displays the image as many times as there are categories, this is the code im putting inside teh foreach statement above
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
if ( ! empty( $terms ) ) {
print '<ul>';
foreach( (array) $terms as $term ) {
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
}
print '</ul>';
}
Any help on this would be great.
Cheers,
the statement
is a replacement for get_terms or get_categories. So you should do something like this