Taxonomy Images
Displaying Your Images in Your Theme 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. Display a single image representing the term archive The following filter will display the image associate
Displaying Your Images in Your Theme
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.
Display a single image representing the term archive
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 for more information about these templates. The simplest use of this filter looks like:
print apply_filters( 'taxonomy-images-queried-term-image', '' );
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:
- after (string) – Text to append to the image’s HTML.
- 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.
- before (string) – Text to prepend to the image’s HTML.
- 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.
Here’s an example of what a fully customized version of this filter might look like:
print apply_filters( 'taxonomy-images-queried-term-image', '', array( 'attr' => array( 'alt' => 'Custom alternative text', 'class' => 'my-class-list bunnies turtles', 'src' => 'this-is-where-the-image-lives.png', 'title' => 'Custom Title', ), 'before' => '<div id="my-custom-div">', 'after' => '</div>', 'image_size' => 'medium' ) );
Similar functionality
If you just need to get the database ID for the image, you may want to use:
$image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
If you need to get the full object of the image, you may want to use:
$image = apply_filters( 'taxonomy-images-queried-term-image-object', '' );