• Resolved creativemanner

    (@creativemanner)


    trying to loop through all the featured images.

    <?php
       while ( have_posts() ) : the_post();
    $attachments = dfi_get_featured_images($post->ID);
    foreach($attachments as $attachment) {
    $medium_img_url = dfi_get_image_url( $attachment['attachment_id'], 'medium' );
    ?>
    <li>
    <a class="gall-img" href="<?php the_permalink() ?>" style="margin-bottom: 0;">
    <img src="<?php echo $medium_img_url; ?>" alt="<?php echo dfi_get_image_alt_by_id($attachment['attachment_id']); ?>" />
    </a>
    </li>
    <?php
    } endwhile;
    ?>

    https://www.ads-software.com/plugins/dynamic-featured-image/

Viewing 1 replies (of 1 total)
  • Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hello creativemanner,

    Thank you for using the plugin. I have tried to explain the code in comments.

    <?php
       //if there is any post
       while ( have_posts() ) : the_post(); //get the psot
    		$attachments = dfi_get_featured_images($post->ID); //dfi_get_featured_images will fetch all DFI images from your post
    		foreach($attachments as $attachment) { //Now loop through your returned image array
    			$medium_img_url = dfi_get_image_url( $attachment['attachment_id'], 'medium' ); //dfi_get_image_url will return medium sized url of your image
    			?>
    			<li>
    				<!-- Display your image. the_permalink() will get the link to your post. dfi_get_image_alt_by_id will get the alt field of your image. -->
    				<a class="gall-img" href="<?php the_permalink() ?>" style="margin-bottom: 0;"> <img src="<?php echo $medium_img_url; ?>" alt="<?php echo dfi_get_image_alt_by_id($attachment['attachment_id']); ?>" /> </a>
    			</li>
    <?php
       } endwhile;
    ?>

    Thanks,
    Ankit

Viewing 1 replies (of 1 total)
  • The topic ‘could you please explain simply how to loop through images.’ is closed to new replies.