0

I'm attempting to display a specific taxonomy (channel) in the archive.php page. I want to display the taxonomy's URL, name, post count, and taxonomy image.

This is what I have that's working so far:

<?php
$taxonomy = 'channel';
$tax_terms = get_terms($taxonomy);
$image_url = print apply_filters( 'taxonomy-images-queried-term-image', '' );
?>

<ul>
    <?php
    foreach ($tax_terms as $tax_term) { ?>

        <li>
            <?php echo esc_attr(get_term_link($tax_term, $taxonomy)); ?>
            <?php echo $tax_term->name; ?>
            <?php echo $tax_term->count; ?>            
            <?php echo $image_url->image_id; ?>
        </li>
    <?php } ?>
</ul>

I've gotten URL, name and post count working, the part that's not working is the taxonomy image provided by the Taxonomy Images plugin. (in the snippet, it's $image_url)

https://wordpress.org/plugins/taxonomy-images/

The plugin provides a image_id for an image added to a taxonomy, the plugin has a ton of ways to get the ID and display the image but I just can't seem to find the correct combination to work with my snippet with my level of skill.

Need some help, thanks.

2 Answers 2

0

Don´t know how this plugin works in detail but i would try this:

<?php
$taxonomy = 'channel';
$tax_terms = get_terms($taxonomy);
?>

    <ul>
    <?php
    foreach ($tax_terms as $tax_term) { ?>

        <li>
            <?php echo esc_attr(get_term_link($tax_term, $taxonomy)); ?>
            <?php echo $tax_term->name; ?>
            <?php echo $tax_term->count; ?>             
            <?php print apply_filters( 'taxonomy-images-queried-term-image', '' ); ?>
        </li>
    <?php } ?>
</ul>
1
  • That didn't work but thanks, I found a better way, placed the answer below.
    – Chozen
    Commented Apr 22, 2017 at 21:07
0

Figured out a better option.

Instead of using Taxonomy Images plugin, Instead, I opted to use the more widely used Categories Images plugin.

https://wordpress.org/plugins/categories-images/

The working code below:

<?php
$taxonomy = 'channel';
$tax_terms = get_terms($taxonomy);

foreach ($tax_terms as $tax_term) { ?>

    <div class="column">
        <?php echo esc_attr(get_term_link($tax_term, $taxonomy)); ?>
        <?php echo $tax_term->name; ?>
        <?php echo $tax_term->count; ?>             
        <?php echo z_taxonomy_image_url($tax_term->term_id); ?>
    </div>
<?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.