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?

  • 
    <?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>';
    			
    			$attachment_id = get_field('field_name');
    			$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
    			$image = wp_get_attachment_image_src( $attachment_id, $size );
    			
    			
    			echo '<img src="' . $image[0] . '" />';
    			
    			echo '<span class="speaker-title">';
    				the_field('title'); echo ' / '; the_field('company_name');
    			echo '</p>';
    			
    			the_content();                    
    	
    	echo '</div>';
    
    endwhile;
    ?>
    

    Straight from the image field docs. Please read the docs