PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/taxonomy-images/readme.md

https://gitlab.com/plusplusminus/htwe
Markdown | 254 lines | 175 code | 79 blank | 0 comment | 0 complexity | 76b8c89b382a9b6dfdca9639c25f162d MD5 | raw file
  1. Taxonomy Images
  2. ===============
  3. A WordPress plugin that enables you to associate images from your media library with categories, tags and custom taxonomies.
  4. Displaying Images in Your Theme
  5. -------------------------------
  6. 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.
  7. Display a single image representing the term archive
  8. ----------------------------------------------------
  9. 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:
  10. ```php
  11. print apply_filters( 'taxonomy-images-queried-term-image', '' );
  12. ```
  13. This code will generate and print an image tag. It's output can be modifed by passing an optional third parameter to apply_filters(). This parameter is an array and the following keys may be set:
  14. * __after__ _(string)_ - Text to append to the image's HTML.
  15. * __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.
  16. * __before__ _(string)_ - Text to prepend to the image's HTML.
  17. * __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.
  18. Here's an example of what a fully customized version of this filter might look like:
  19. ```php
  20. print apply_filters( 'taxonomy-images-queried-term-image', '', array(
  21. 'attr' => array(
  22. 'alt' => 'Custom alternative text',
  23. 'class' => 'my-class-list bunnies turtles',
  24. 'src' => 'this-is-where-the-image-lives.png',
  25. 'title' => 'Custom Title',
  26. ),
  27. 'before' => '<div id="my-custom-div">',
  28. 'after' => '</div>',
  29. 'image_size' => 'medium'
  30. ) );
  31. ```
  32. Similar functionality
  33. ---------------------
  34. If you just need to get the database ID for the image, you may want to use:
  35. ```php
  36. $image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
  37. ```
  38. If you need to get the full object of the image, you may want to use:
  39. ```php
  40. $image = apply_filters( 'taxonomy-images-queried-term-image-object', '' );
  41. ```
  42. If you need to get the URL to the image, you may want to use the following:
  43. ```php
  44. $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
  45. ```
  46. You can specify the size of the image in an option third parameter:
  47. ```php
  48. $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array(
  49. 'image_size' => 'medium'
  50. ) );
  51. ```
  52. If you need data about the image, you may want to use:
  53. ```php
  54. $image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '' );
  55. ```
  56. You can specify the size of the image in an option third parameter:
  57. ```php
  58. $image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '', array(
  59. 'image_size' => 'medium'
  60. ) );
  61. ```
  62. List term images associated with a post object
  63. ----------------------------------------------
  64. When a post is being displayed you may want to display the images associated with all of the terms associated with the post. The `taxonomy-images-list-the-terms` filter does this. Here's what it looks like in its simplest form:
  65. ```php
  66. print apply_filters( 'taxonomy-images-list-the-terms', '' );
  67. ```
  68. This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:
  69. * __after__ _(string)_ - Text to append to the output. Default value is a closing unordered list tag.
  70. * __after_image__ _(string)_ - Text to append to each image. Default value is a closing list-item tag.
  71. * __before__ _(string)_ - Text to prepend to the output. Default value is an open unordered list tag with an class attribute of "taxonomy-images-the-terms".
  72. * __before_image__ _(string)_ - Text to prepend to each image. Default value is an open list-item tag.
  73. * __image_size__ _(string)_ - Any registered image size. Values will vary from installation to installation. Image sizes defined in core include: "thumbnail", "medium" and "large". "full" may also be used to get the unmodified image that was uploaded. Defaults to "thumbnail".
  74. * __post_id__ _(int)_ - The post to retrieve terms from. Defaults to the ID property of the global `$post object`.
  75. * __taxonomy__ _(string)_ - Name of a registered taxonomy to return terms from. Defaults to `category`.
  76. Here's an example of what a fully customized version of this filter might look like:
  77. ```php
  78. print apply_filters( 'taxonomy-images-list-the-terms', '', array(
  79. 'before' => '<div class="my-custom-class-name">',
  80. 'after' => '</div>',
  81. 'before_image' => '<span>',
  82. 'after_image' => '</span>',
  83. 'image_size' => 'detail',
  84. 'post_id' => 1234,
  85. 'taxonomy' => 'post_tag',
  86. ) );
  87. ```
  88. Working with all terms of a given taxonomy
  89. ------------------------------------------
  90. 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:
  91. ```php
  92. $terms = apply_filters( 'taxonomy-images-get-terms', '' );
  93. ```
  94. Here is what php's `print_r()` function may return:
  95. ```
  96. Array
  97. (
  98. [0] => stdClass Object
  99. (
  100. [term_id] => 8
  101. [name] => Pirate
  102. [slug] => pirate
  103. [term_group] => 0
  104. [term_taxonomy_id] => 8
  105. [taxonomy] => category
  106. [description] => Pirates live in the ocean and ride around on boats.
  107. [parent] => 0
  108. [count] => 1
  109. [image_id] => 44
  110. )
  111. )
  112. ```
  113. As you can see, all of the goodness of `get_terms()` is there with an added bonus: the `image_id` parameter!
  114. This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:
  115. * __cache_images__ _(bool)_ If this value is `true` all associated images will be queried 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`.
  116. * __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`.
  117. * __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`.
  118. * __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.
  119. Here's an example of a simple custom loop that you can use to display all term images:
  120. ```php
  121. $terms = apply_filters( 'taxonomy-images-get-terms', '' );
  122. if ( ! empty( $terms ) ) {
  123. print '<ul>';
  124. foreach ( (array) $terms as $term ) {
  125. print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
  126. }
  127. print '</ul>';
  128. }
  129. ```
  130. Support
  131. -------
  132. If you have questions about integrating this plugin into your site, please [add a new thread to the WordPress Support Forum](https://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.
  133. Bugs, Suggestions
  134. -----------------
  135. Development of this plugin is hosted in a public repository on [Github](https://github.com/benhuson/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/benhuson/Taxonomy-Images/issues/new)
  136. Hook it up yo!
  137. ---------------
  138. 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!_:
  139. * __Rate it!__ - Use the star tool on the right-hand sidebar of the [plugin homepage](https://wordpress.org/plugins/taxonomy-images/).
  140. * __Let me know if it works__ - Use the _Compatibility_ widget on the [plugin homepage](https://wordpress.org/plugins/taxonomy-images/) to let everyone know that the current version works with your version of WordPress.
  141. * __Do you Twitter?__ Help promote by using this shortlink: [http://bit.ly/taxonomy-images](http://bit.ly/taxonomy-images)
  142. * __Are you a writer?__ Help promote by writing an article on your website about this plugin.
  143. Need More Taxonomy Plugins?
  144. ---------------------------
  145. The original author of this plugin, Michael Fields, released a handful of plugins dealing with taxonomies. Please see his [WordPress.org profile](https://profiles.wordpress.org/mfields/) for more information.
  146. Installation
  147. ------------
  148. 1. Download
  149. 1. Unzip the package and upload to your `/wp-content/plugins/` directory.
  150. 1. Log into WordPress and navigate to the "Plugins" panel.
  151. 1. Activate the plugin.
  152. 1. Click the "Taxonomy Images" link under the Settings section in the admin menu. There you can select the taxonomies that you would like to add image support for.
  153. Upgrade Notice
  154. --------------
  155. ### 0.9.6
  156. Fixed issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
  157. ### 0.9.5
  158. Fix loading of admin stylesheet when editing terms in WordPress 4.5
  159. ### 0.9.4
  160. Fix for taxonomy names that may contain characters other than lowercase and underscores (e.g. uppercase).
  161. ### 0.9.3
  162. Fix post permissions error when using media modal.
  163. ### 0.9.2
  164. Fix old and new media modal opening simultaneously in some circumstances.
  165. ### 0.9.1
  166. Fixes media modal not opening on newly created terms.
  167. ### 0.9
  168. Fixes media modal for newer versions of WordPress. Tested up to WordPress 4.3.1 (requires 3.4+).
  169. ### 0.8
  170. Major and minor bug fixes tested with WordPress 3.6.
  171. ### 0.7
  172. Complete rewrite. Better everything. Many bug fixes.
  173. Changelog
  174. ---------
  175. View a list of all plugin changes in [CHANGELOG.md](https://github.com/benhuson/Taxonomy-Images/blob/master/CHANGELOG.md).