title: Wordpress Category image display
body: <p>I am using a script found at <a href="http://wpdevsnippets.com/add-category-tag-taxonomy-picture/" rel="nofollow">http://wpdevsnippets.com/add-category-tag-taxonomy-picture/</a>.  However, I cannot get the writer to answer a usage question, so here it is:</p>
  
  <p>How do I use this script with a custom taxonomy on a page.php or archive.php template?</p>
  
  <pre><code>add_action('admin_head', 'wpds_admin_head');
  add_action('edit_term', 'wpds_save_tax_pic');
  add_action('create_term', 'wpds_save_tax_pic');
  function wpds_admin_head() {
  $taxonomies = get_taxonomies();
  //$taxonomies = array('category'); // uncomment and specify particular taxonomies you want to add image feature.
  if (is_array($taxonomies)) {
      foreach ($taxonomies as $z_taxonomy) {
          add_action($z_taxonomy . '_add_form_fields', 'wpds_tax_field');
          add_action($z_taxonomy . '_edit_form_fields', 'wpds_tax_field');
      }
  }
  }
  
  // add image field in add form
  function wpds_tax_field($taxonomy) {
  wp_enqueue_style('thickbox');
  wp_enqueue_script('thickbox');
  if(empty($taxonomy)) {
      echo '&lt;div class="form-field"&gt;
              &lt;label for="wpds_tax_pic"&gt;Picture&lt;/label&gt;
              &lt;input type="text" name="wpds_tax_pic" id="wpds_tax_pic" value="" /&gt;
          &lt;/div&gt;';
  }
  else{
      $wpds_tax_pic_url = get_option('wpds_tax_pic' . $taxonomy-&gt;term_id);
      echo '&lt;tr class="form-field"&gt;
      &lt;th scope="row" valign="top"&gt;&lt;label for="wpds_tax_pic"&gt;Picture&lt;/label&gt;&lt;/th&gt;
      &lt;td&gt;&lt;input type="text" name="wpds_tax_pic" id="wpds_tax_pic" value="' . $wpds_tax_pic_url . '" /&gt;&lt;br /&gt;';
      if(!empty($wpds_tax_pic_url))
          echo '&lt;img src="'.$wpds_tax_pic_url.'" style="max-width:200px;border: 1px solid #ccc;padding: 5px;box-shadow: 5px 5px 10px #ccc;margin-top: 10px;" &gt;';
      echo '&lt;/td&gt;&lt;/tr&gt;';        
  }
  echo '&lt;script type="text/javascript"&gt;
      jQuery(document).ready(function() {
              jQuery("#wpds_tax_pic").click(function() {
                  tb_show("", "media-upload.php?type=image&amp;amp;TB_iframe=true");
                  return false;
              });
              window.send_to_editor = function(html) {
                  jQuery("#wpds_tax_pic").val( jQuery("img",html).attr("src") );
                  tb_remove();
              }
      });
  &lt;/script&gt;';
  }
  
  // save our taxonomy image while edit or save term
  function wpds_save_tax_pic($term_id) {
  if (isset($_POST['wpds_tax_pic']))
      update_option('wpds_tax_pic' . $term_id, $_POST['wpds_tax_pic']);
  }
  
  // output taxonomy image url for the given term_id (NULL by default)
  function wpds_tax_pic_url($term_id = NULL) {
  if ($term_id) 
      return get_option('wpds_tax_pic' . $term_id);
  elseif (is_category())
      return get_option('wpds_tax_pic' . get_query_var('cat')) ;
  elseif (is_tax()) {
      $current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
      return get_option('wpds_tax_pic' . $current_term-&gt;term_id);
  }
  }
  </code></pre>
  
  <p>And here is the function that is used to call this:</p>
  
  <pre><code>wpds_tax_pic_url();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>wpds_tax_pic_url($category-&gt;cat_ID);
  </code></pre>
  
  <p>How do I use this script with a custom taxonomy on a page.php or archive.php template?</p>