$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to display custom taxonomy images on index.php?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to display custom taxonomy images on index.php?

matteradmin9PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far