How to display custom taxonomy images on index.php?

admin2025-06-02  2

i want to display custom taxonomy images on index.php and for this reason i installed this plugin. I uploaded my taxonomy images but i couldn't display images on index. I tried the codes which are given by the plugin author.

    <?php
print apply_filters( 'taxonomy-images-queried-term-image', '' );
?>

etc. But it didn't work. I think this code has no echo function, am i right? And the URL, which you can see the below, is my custom taxonomy URL.

edit-tags.php?taxonomy=ff-portfolio-tag&post_type=portfolio

So how can i display my custom taxonomy images on index.php? Thanks a lot.

i want to display custom taxonomy images on index.php and for this reason i installed this plugin. I uploaded my taxonomy images but i couldn't display images on index. I tried the codes which are given by the plugin author.

    <?php
print apply_filters( 'taxonomy-images-queried-term-image', '' );
?>

etc. But it didn't work. I think this code has no echo function, am i right? And the URL, which you can see the below, is my custom taxonomy URL.

edit-tags.php?taxonomy=ff-portfolio-tag&post_type=portfolio

So how can i display my custom taxonomy images on index.php? Thanks a lot.

Share Improve this question asked Aug 12, 2016 at 19:55 KatzenliebeKatzenliebe 251 gold badge1 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Just like we use get_terms() to get all the terms in a custom taxonomy we can get all the taxonomy images with the below code. Place this code outside the loop to list all the taxonomy images.

$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    'taxonomy'     => 'ff-portfolio-tag',
) );
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' ) . '</li>';
    }
    print '</ul>';
}

Are you looking at a taxonomy archive page? You mention you want to display it on index.php, but since a theme can technically have only that template for all possible URLs that doesn't really give meaningful information.

As the note on the plugin page says, that filter is for displaying the images on a page that has a term in its context, so if you aren't trying to view a taxonomy archive or similar then it won't work.

I use this plugin all the time and as long as you dig into the documentation, everything is pretty clear.

Try:

$terms = apply_filters( 
    'taxonomy-images-get-terms', 
    '', 
    array( 
        'taxonomy' => 'ff-portfolio-tag',
    ) 
);
print_r( $terms );

... for example.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748857301a314298.html

最新回复(0)