Support

Account

Home Forums Front-end Issues Display image

Solving

Display image

  • Hi everybody,

    Sorry for my English cause i’m French 😉

    So, i’ve a little problem to display an custom taxonomy image in custom archive page.
    I use this code to display it

    <?php 
                                    $args = array( 'hide_empty' => 0,
                                            'parent'          => 0,
                                        );
    
                                    $terms = get_terms( 'taxonomy_ascenseur', $args );
                                    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
                                        echo '<ul>';
                                        foreach ( $terms as $term ) {
                                          echo '<li><img src="'. the_field("image_categorie",$term) .'"/>' . $term->name . '</li>';
                                        }
                                        echo '</ul>';
                                    }
                            ?>

    But it no displaying an image but just the url outside the “img” balise.
    It display Something like this :

    <ul>
    http://localhost:8888/website/wp-content/uploads/2015/11/ascenseur2.jpg
    <li>
    <img src="">
    Cat1
    </li>
    </ul>

    I don’t understand why because if i put the image url directly in the <img src="" /> it work.

  • You’re not using the correct id for the field

    
    <?php 
      $args = array(
        'hide_empty' => 0,
        'parent' => 0,
      );
      
      $terms = get_terms( 'taxonomy_ascenseur', $args );
      if (!empty($terms) && !is_wp_error($terms)) {
        echo '<ul>';
        foreach ( $terms as $term ) {
          echo '<li><img src="'.
            the_field('image_categorie', 'taxonomy_ascenseur_'.$term->term_id).
            '"/>'.$term->name.'</li>';
        }
        echo '</ul>';
      }
    ?>
    

    In the future you should not reply to your own question. Doing so takes it off the list of question that need a reply so it looks like someone is already helping you. Bumping questions won’t get them answered faster and doing so will hurt your chances of getting a reply.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Display image’ is closed to new replies.