WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
how to avoid warning notice "taxonomy does not have image support"? (3 posts)

  1. berteh
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/taxonomy-images/

  2. berteh
    Member
    Posted 1 year ago #

    2 quick edits to the above:

    1) need to add , 'having_images' => false just after 'post_id' => $id for enabling terms with no images to shown when some other terms in the same taxonomy have images associated... as they don't show by default.

    2) need to add </a> just before </li> as I forgot the closing tag... sorry.

    Any improvement suggestion is welcome... and my problem remains: how to workaround the "warning" generated by this plugin when taxonomy-images-get-the-terms is called on a taxonomy for which the taxonomy-images is not activated?

    B.

  3. berteh
    Member
    Posted 1 year ago #

    bump: how to workaround the "warning" generated by this plugin when taxonomy-images-get-the-terms is called on a taxonomy for which the taxonomy-images function is not activated?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic