how to avoid warning notice "taxonomy does not have image support"?
-
Hello,
Thank you very much for this excellent plugin. Works fine with WP3.5.1.I want to automate the display of images for all terms of all taxonomies that have an image associated. Unfortunately your plugin raise a warning for taxonomies for which taxonomy-images has not be activated.
Could you please tell me how to hide this warning as it is displayed on the blog in public… or add a test function to your code “taxonomy-images-is-active-for-taxonomy”? As it is a warning and not an error I cannot try/catch it.
For info / other users my code for displaying all terms images is below, terms with no images get displayed as text links (to be put in your template
functions.php
.function custom_taxonomies_terms_links_images() { $id = get_the_ID(); $post_type = get_post_type($id); $taxonomies = get_object_taxonomies($post_type); $out_images = $out_texts = array(); foreach ($taxonomies as $taxonomy) { //if ($taxonomy == 'post_format') //internal WP3.1+ taxonomy, skip. // continue; //next filter shows notice on blog if images not activated for taxonomy $terms = apply_filters( 'taxonomy-images-get-the-terms', '', array( 'taxonomy' => $taxonomy, 'post_id' => $id ) ); // if the above rises a warning, then images are not activated for this taxonomy, then populate terms with: // $terms = get_the_terms( $id, $taxonomy ); if ( !empty( $terms ) ) { foreach ( $terms as $term ) if (!empty($term->image_id)) { $out_images[] = '<li class="taxonomy-image"><a href="' . esc_url( get_term_link( $term, $taxonomy ) ) . '" title="'.$term->name.' ('.$taxonomy.')">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>'; } else $out_texts[] = '<a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a>'; } } if ($out_texts) $out_images[] = '<li class="taxonomy-text">'.join( ', ', $out_texts).'</li>'; return '<ul class="taxonomy-images-the-terms">'.join( '', $out_images).'</ul>'; }
simply call it with
<?php echo custom_taxonomies_terms_links_images(); ?>
wherever the loop is displaying the categories of a post, for instance.
- The topic ‘how to avoid warning notice "taxonomy does not have image support"?’ is closed to new replies.