The Taxonomy Images plugin allows you to associate images from your Media Library to categories, tags and custom taxonomies. For usage instructions please view the [screencast](http://screenr.com/zMx).

14

15

= Displaying Images in a Page or Post =

16

17

Version 0.4 introduces a new shortcode which will display a list of all active terms of a given taxonomy. This list features the term in a second level heading `<h2>`, the term description in a paragraph and an intermediate version of the uploaded image floated to the left. Here is the shortcode in it's simplist form:

18

19

`[taxonomy_image_plugin]`

20

21

This will display a list of all terms in the built-in "Category" taxonomy with desriptions and images (sized as "thumbnails").

22

23

If you would like to change the taxonomy, you can set the "taxonomy" argument:

To display the images in your theme, you will want to use the following code in the appropriate theme file. The correct file will vary depending on your theme. category.php, tag.php, archive.php are a few file that this code will work in. Please see [Template Hierarchy](http://codex.wordpress.org/Template_Hierarchy) for more information.

Here we have passed to arguments to the WordPress core function do_action(). The first is `taxonomy_image_plugin_print_image_html` and should not be changed. The second represents the size of the image that you would like displayed. Acceptable values are:

38

39

* detail

40

* thumbnail

41

* medium

42

* large

43

* fullsize

44

45

= Displaying Images in your Theme #2: Category Thumbs =

46

47

The following example was inspired by [this thread](http://wordpress.org/support/topic/364299) in the WordPress.org Support Fourms. This code can be placed inside any theme template and will produce a string of links for every taxonomy that has an associated image.

There are a few filters that you can use in your theme to display the image associations created by this plugin. Please read below for detailed information.

19

20

= Display a single image representing the term archive =

21

22

The following filter will display the image associated with the term asked for in the query string of the url. This filter only works in views that naturally use templates like category.php, tag.php taxonomy.php and all of their derivatives. Please read about [template hierarchy](http://codex.wordpress.org/Template_Hierarchy) for more information about these templates. The simplest use of this filter looks like:

23

24

`print apply_filters( 'taxonomy-images-queried-term-image', '' );`

25

26

This code will generate and print an image tag. It's output can be modifed by passig an optional third parameter to apply filters. This parameter is an array and the following keys may be set:

27

28

* __after__ (string) - Text to append to the image's HTML.

29

30

* __attr__ (array) - Key/value pairs representing the attributes of the img tag. Available options include: alt, class, src and title. This array will be passed as the fourth parameter to WordPress core function wp_get_attachment_image() without modification.

31

32

* __before__ (string) - Text to prepend to the image's HTML.

33

34

* __image_size__ (string) - May be any image size registered with WordPress. If no image size is specified, 'thumbnail' will be used as a default value. In the event that an unregistered size is specified, this filter will return an empty string.

35

36

Here's an example of what a fully customized version of this filter might look like:

When a post is being displayed you may want to display all of the images associated with all of the terms that are associated with the post (a mouthful? Yes indeed!). The `taxonomy-images-list-the-terms` filter does this. Here's what it looks like in its simplest form:

88

89

`print apply_filters( 'taxonomy-images-list-the-terms', '' );`

90

91

This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:

* __before__ (string) - Text to prepend to the output. Default value is an open unordered list element with an class attribute of "taxonomy-images-the-terms".

98

99

* __before_image__ (string) - Text to prepend to each image. Default value is an open list-item element.

100

101

* __image_size__ (string) - Any registered image size. Values will vary from installation to installation. Image sizes defined in core include: "thumbnail", "medium" and "large". "Fullsize" may also be used to get the unmodified image that was uploaded. Defaults to "thumbnail".

102

103

* __post_id__ (int) - The post to retrieve terms from. Defaults to the ID property of the global $post object.

104

105

* __taxonomy__ (string) - Name of a registered taxonomy to return terms from. Defaults to "category".

106

107

Here's an example of what a fully customized version of this filter might look like:

108

109

`

110

print apply_filters( 'taxonomy-images-list-the-terms', '', array(

111

'after' => '</div>',

112

'after_image' => '</span>',

113

'before' => '<div class="my-custom-class-name">',

114

'before_image' => '<span>',

115

'image_size' => 'detail',

116

'post_id' => 1234,

117

'taxonomy' => 'post_tag',

118

) );

119

`

120

121

= Working with all terms of a given taxonomy =

122

123

You will want to use the 'taxonomy-images-get-terms' filter. This filter is basically a wrapper for WordPress core function [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms). It will return an array of enhanced term objects: each term object will have a custom property named image_id which is an integer representing the database ID of the image associated with the term. This filter can be used to create custom lists of terms. Here's what it's default useage looks like:

124

125

`$terms = apply_filters( 'taxonomy-images-get-terms', '' );`

126

127

Here is what php's print_r() function may return:

128

129

`

130

Array

131

(

132

[0] => stdClass Object

133

(

134

[term_id] => 8

135

[name] => Pirate

136

[slug] => pirate

137

[term_group] => 0

138

[term_taxonomy_id] => 8

139

[taxonomy] => category

140

[description] => Pirates live in the ocean and ride around on boats.

141

[parent] => 0

142

[count] => 1

143

[image_id] => 44

144

)

145

)

146

`

147

148

As you can see, all of the goodness of get_terms() is there with an added bonus: the image_id parameter!

149

150

This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:

151

152

* __cache_images__ (bool) If this value is true all assocaite images will be queried for and cached for later use in various template tags. If it is set to false, this query will be suppressed. Do not set this value to false unless you have a really good reason for doing so :) Default value is true.

153

154

* __having_images__ (bool) If this value is true then only terms that have associated images will be returned. Setting it to false will return all terms. Default value is true.

155

156

* __taxonomy__ (string) Name of a registered taxonomy to return terms from. Multiple taxonomies may be specified by separating each name by a comma. Defaults to "category".

157

158

* __term_args__ (array) Arguments to pass to [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms) as the second parameter. Default value is an empty array.

159

160

Here's and example of a simple custom loop that you can make to display all term images:

If you find that this plugin is has a bug, does not play nicely with other plugins or if you have a suggestion or comment, please <a href="http://wordpress.org/tags/taxonomy-images?forum_id=10#postform">use this link to add a new thread to the WordPress Support Forum</a>

175

If you have questions about integrating this plugin into your site, please [add a new thread to the WordPress Support Forum](http://wordpress.org/tags/taxonomy-images?forum_id=10#postform). I try to answer these, but I may not always be able to. In the event that I cannot there may be someone else who can help.

176

177

= Bugs, Suggestions =

178

179

Development of this plugin is hosted in a public repository on [Github](https://github.com/mfields/Taxonomy-Images). If you find a bug in this plugin or have a suggestion to make it better, please [create a new issue](https://github.com/mfields/Taxonomy-Images/issues/new)

If you have fallen in love with this plugin and would not be able to sleep without helping out in some way, please see the following list of ways that you can _hook it up!_:

64

184

65

* __Rate it!__ - use the star tool on the right-hand sidebar of the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/) to tells me what you think.

66

* __Let me know if it works__ - Use the _Compatibility_ widget on the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/) to let me know that the current version works with your version of WordPress.

185

* __Rate it!__ - Use the star tool on the right-hand sidebar of the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/).

186

187

* __Let me know if it works__ - Use the _Compatibility_ widget on the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/) to let everyone know that the current version works with your version of WordPress.

188

67

189

* __Do you Twitter?__ Help promote by using this shortlink: [http://bit.ly/taxonomy-images](http://bit.ly/taxonomy-images)

190

68

191

* __Are you a writer?__ Help promote by writing an article on your website about this plugin.

69

* __Are you Super-Wicked-Awesome?__ If so, you can always [make a donation](http://mfields.org/donate/).

192

193

* __Are you Super-Wicked-Awesome?__ If so, you can always [make a donation](http://wordpress.mfields.org/donate/).