Support

Account

Home Forums Front-end Issues How to display image field in a loop? Reply To: How to display image field in a loop?

  • Hi @Marzo

    Please read the code examples for the image field:
    http://www.advancedcustomfields.com/resources/field-types/image/

    if your image field returned a simple URL, the following code would work:

    
    <?php
    $args = array( 'post_type' => 'speakers', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    
    while ( $loop->have_posts() ) : $loop->the_post();
    	echo '<div class="entry-content">';
    		echo '<h2 class="speaker-name">';
    			the_title();
    		echo '</h2>';
    			
    			echo '<img src="' . get_field('field_name') . '" alt="" />';
    			
    			echo '<span class="speaker-title">';
    				the_field('title'); echo ' / '; the_field('company_name');
    			echo '</p>';
    			
    			the_content();                    
    	
    	echo '</div>';
    
    endwhile;
    ?>