I want to show images in my single-content.php
file. I have almost 20 to 25 images in every post. I want to print them with below code one by one. I have to change one line in code for every image for uniqueness so that's why I need to print them one by one not all in one loop.
I have code but I'm unable to add option for next image to print. I mean when I copy and paste the same code same image is printed again. So basically I need help here. How can I get next image when I paste code again and again for 20 time or 25 times to get all images. Hope I can describe my problem. (Sorry for my bad english.)
/* ATTACHMENT*/
$args = array(
'numberposts' => -1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $posid,
'post_status' => null,
'post_type' => 'attachment',
);
$atts = get_children( $args );
$tatts = count($atts);
$i = 1;
foreach ($atts as $at)
$atid = $at->ID;
$mimg = wp_get_attachment_image_src($atid,'large');
$msrc = $mimg[0];
$mw = $mimg[1];
$mh = $mimg[2];
$atslug = $at->post_name;
$aturl = $surl.'/'.$poslug.'/'.$atslug.'/';
echo ' <img class="mdi" src="'.$msrc.'" /> ';
In other way I need a code that can display images in my post one by one (I know I can insert images in my post, but I want to just upload images to post and my code fetch images for me as I have to apply a php code for images as above code do same the code fetch images that attached to post ) like in my file template I put code like this, for ex: my all posts has 3 images so I want code like this:
<?php image 1 code here?>
<?php image 2 code here?>
<?php image 3 code here ?>