T
T
there42018-06-09 08:28:17
WordPress
there4, 2018-06-09 08:28:17

How to display an image in your taxonomy?

Displaying my own taxonomy created in function.php using get_the_term_list

/**
 * Создание собственной таксономии
 */
function create_my_taxonomies() {
  register_taxonomy('actors', 'post', array(
  'hierarchical' => false, 'label' => 'Участники',
  'query_var' => true, 'rewrite' => true));
}
add_action('init', 'create_my_taxonomies', 0);

<?php echo get_the_term_list($post->ID, 'actors', '<h3>Участники</h3>', '<br/>', ''); ?>

I want to add a taxonomy image there, I created a new image taxonomy with the Advanced Custom Fields imgcat1 plugin , added an image to the taxonomy
. Now I'm trying to display:
function tax_img() {
  $imgcat1 = get_field("imgcat1") ;
    echo get_the_term_list($post->ID, 'actors', '<h3>Участники</h3>', '<img src="'.$imgcat1.'"/>'.'<br/>', '');
}

It doesn't work... it returns unknown instead of the picture How
to get the value of the imgcat1 field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
there4, 2018-06-09
@there4

function tax_img() {
  $cur_terms = get_the_terms( $post->ID, 'actors' );
  foreach( $cur_terms as $cur_term ){
    echo '<img src="';
    the_field( 'imgtax', $cur_term );
    echo '"/>';
    echo '<a href="'. get_term_link( (int)$cur_term->term_id, $cur_term->taxonomy ) .'">'. $cur_term->name .'</a><br>';
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question