开发者 |
mfields
husobj jamiemchale |
---|---|
更新时间 | 2024年2月16日 02:12 |
捐献地址: | 去捐款 |
PHP版本: | 4.4 及以上 |
WordPress版本: | 6.4.3 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
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:
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.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', '' );
If you need to get the URL to the image, you may want to use the following:
$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
You can specify the size of the image in an option third parameter:
$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array( 'image_size' => 'medium' ) );
If you need data about the image, you may want to use:
$image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '' );
You can specify the size of the image in an option third parameter:
$image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '', array( 'image_size' => 'medium' ) );
List term images associated with a post object
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:
print apply_filters( 'taxonomy-images-list-the-terms', '' );
This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:
$post
object.category
.print apply_filters( 'taxonomy-images-list-the-terms', '', array( 'before' => '<div class="my-custom-class-name">', 'after' => '</div>', 'before_image' => '<span>', 'after_image' => '</span>', 'image_size' => 'detail', 'post_id' => 1234, 'taxonomy' => 'post_tag', ) );
Working with all terms of a given taxonomy
You will want to use the taxonomy-images-get-terms
filter. This filter is basically a wrapper for WordPress core function 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:
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
Here is what php's print_r()
function may return:
Array ( [0] => stdClass Object ( [term_id] => 8 [name] => Pirate [slug] => pirate [term_group] => 0 [term_taxonomy_id] => 8 [taxonomy] => category [description] => Pirates live in the ocean and ride around on boats. [parent] => 0 [count] => 1 [image_id] => 44 ) )
As you can see, all of the goodness of get_terms()
is there with an added bonus: the image_id
parameter!
This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:
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
.true
then only terms that have associated images will be returned. Setting it to false
will return all terms. Default value is true
.category
.get_terms()
as the second parameter. Default value is an empty array.$terms = apply_filters( 'taxonomy-images-get-terms', '' ); if ( ! empty( $terms ) ) { print '<ul>'; foreach ( (array) $terms as $term ) { print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a></li>'; } print '</ul>'; }
技术支持
If you have questions about integrating this plugin into your site, please add a new thread to the WordPress Support Forum. 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.
Bugs, Suggestions
Development of this plugin is hosted in a public repository on Github. If you find a bug in this plugin or have a suggestion to make it better, please create a new issue
Hook it up yo!
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!:
/wp-content/plugins/
directory.images
folder.image_resize
function.image_resize()
function.screen_icon()
function.jQuery.on()
instead of jQuery.live()
. Props jamiemchale.taxonomy_images_plugin_get_the_terms()
and taxonomy_images_plugin_list_the_terms()
.button-primary
.get_posts()
in a variable called $images
. Not sure why, but this should not harm anything.GPLv2 or later
for maximum flexibility and compatibility..pot
file and languages directory.edit-tag.php
has been introduced.get_image_html()
Now populates the image's alt
attribute with appropriate data. Props to jaygoldman.is_taxonomy()
- props to anointed.taxonomy_exists()
function for backwards compatibility with 2.9 branch. This function is new in WordPress version 3.0._tag_row()
.get_thumb()
now returns the fullsize URL if there is no appropriate intermediate image.register_deactivation_hook()
function - sorry to all 8 who downloaded this plugin so far :)category_rows
method to 15. This allows this plugin to be compatible with Reveal IDs for WP Admin. Thanks to Peter Kahoun$settings
and $locale
are now public properties.$taxonomy_images_plugin
.$term_tax_id
to both print_image_html()
and get_image_html()
.