I’m using Taxonomy Images to associate images with categories. I’m using the following code, one is to display the categories, the other to display the images.
Here is the code that displays my categories.
<?php
$cat_id = get_query_var('cat');
$catlist = get_categories('hide_empty=0&child_of=' . $cat_id);
echo "<ul>";
foreach($catlist as $categories_item)
{
echo '<h1><a href="' . get_category_link( $categories_item->term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $categories_item->name ) . '" ' . '>' . $categories_item->name.'</a> </h1> ';
echo '<p>'. $categories_item->description . '</p>';
}
echo "</ul>";
}
?>
Here is the code that displays the images.
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
if ( ! empty( $terms ) ) {
foreach( (array) $terms as $term ) {
print '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' );
}
}
If i put the image code above the foreach for the categories it will show the images above my categories. If i put the image code below the end of the foreach for the categories it will show the images below the categories.
If i put the image code inside the foreach for the category it will show the all of the images under every category. So under the first category it will show the image for all categories and it will do the same under all of the other categories.
How can i combine both pieces of code so it will display the category, the image associated with that category then the second category and the image associated with that category?
I’ve tried the answer below but the image code doesn’t work without the foreach $terms as $term, so i’m still stuck trying to do this.
No luck by using plugin provided functions as it gets it’s id by
To get the image I use this code snippet:
Just got this work out today by the code below.
I use get_option( ‘taxonomy_image_plugin’ ) to get an association between term_id and attachment_id, after that everything works like a charm.
As described via the plugins wordpress download page instructions:
e.g.
Got this working by using the code below. It will show the categories and the image associated with it.