How to Get next image with my this code from same post -(wordpress)












0















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 5 images so I want code like this:



    <img src'<?php first-attachment-url ?>')"> 
<img src'<?php second-attachment-url ?>')">
<img src'<?php third-attachment-url ?>')">
<img src'<?php fourth-attachment-url ?>')">
<img src'<?php fifth-attachment-url ?>')">









share|improve this question





























    0















    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 5 images so I want code like this:



        <img src'<?php first-attachment-url ?>')"> 
    <img src'<?php second-attachment-url ?>')">
    <img src'<?php third-attachment-url ?>')">
    <img src'<?php fourth-attachment-url ?>')">
    <img src'<?php fifth-attachment-url ?>')">









    share|improve this question



























      0












      0








      0








      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 5 images so I want code like this:



          <img src'<?php first-attachment-url ?>')"> 
      <img src'<?php second-attachment-url ?>')">
      <img src'<?php third-attachment-url ?>')">
      <img src'<?php fourth-attachment-url ?>')">
      <img src'<?php fifth-attachment-url ?>')">









      share|improve this question
















      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 5 images so I want code like this:



          <img src'<?php first-attachment-url ?>')"> 
      <img src'<?php second-attachment-url ?>')">
      <img src'<?php third-attachment-url ?>')">
      <img src'<?php fourth-attachment-url ?>')">
      <img src'<?php fifth-attachment-url ?>')">






      php wordpress






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 17:45







      deccc

















      asked Nov 24 '18 at 16:36









      decccdeccc

      276




      276
























          1 Answer
          1






          active

          oldest

          votes


















          0














          a bit modification of your code



          <?php
          $args = array(

          'numberposts' => -1,

          'order' => 'ASC',

          'post_mime_type' => 'image',

          'post_parent' => get_the_ID(),

          '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.'" /> ';
          }


          ?>


          please let me know if it's like what you want or not






          share|improve this answer
























          • thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

            – deccc
            Nov 25 '18 at 6:18











          • is their any possibility to achieve this in wordpress ?

            – deccc
            Nov 25 '18 at 15:24













          • sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

            – rheeantz
            Dec 1 '18 at 5:25











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460205%2fhow-to-get-next-image-with-my-this-code-from-same-post-wordpress%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          a bit modification of your code



          <?php
          $args = array(

          'numberposts' => -1,

          'order' => 'ASC',

          'post_mime_type' => 'image',

          'post_parent' => get_the_ID(),

          '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.'" /> ';
          }


          ?>


          please let me know if it's like what you want or not






          share|improve this answer
























          • thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

            – deccc
            Nov 25 '18 at 6:18











          • is their any possibility to achieve this in wordpress ?

            – deccc
            Nov 25 '18 at 15:24













          • sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

            – rheeantz
            Dec 1 '18 at 5:25
















          0














          a bit modification of your code



          <?php
          $args = array(

          'numberposts' => -1,

          'order' => 'ASC',

          'post_mime_type' => 'image',

          'post_parent' => get_the_ID(),

          '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.'" /> ';
          }


          ?>


          please let me know if it's like what you want or not






          share|improve this answer
























          • thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

            – deccc
            Nov 25 '18 at 6:18











          • is their any possibility to achieve this in wordpress ?

            – deccc
            Nov 25 '18 at 15:24













          • sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

            – rheeantz
            Dec 1 '18 at 5:25














          0












          0








          0







          a bit modification of your code



          <?php
          $args = array(

          'numberposts' => -1,

          'order' => 'ASC',

          'post_mime_type' => 'image',

          'post_parent' => get_the_ID(),

          '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.'" /> ';
          }


          ?>


          please let me know if it's like what you want or not






          share|improve this answer













          a bit modification of your code



          <?php
          $args = array(

          'numberposts' => -1,

          'order' => 'ASC',

          'post_mime_type' => 'image',

          'post_parent' => get_the_ID(),

          '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.'" /> ';
          }


          ?>


          please let me know if it's like what you want or not







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 21:05









          rheeantzrheeantz

          709412




          709412













          • thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

            – deccc
            Nov 25 '18 at 6:18











          • is their any possibility to achieve this in wordpress ?

            – deccc
            Nov 25 '18 at 15:24













          • sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

            – rheeantz
            Dec 1 '18 at 5:25



















          • thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

            – deccc
            Nov 25 '18 at 6:18











          • is their any possibility to achieve this in wordpress ?

            – deccc
            Nov 25 '18 at 15:24













          • sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

            – rheeantz
            Dec 1 '18 at 5:25

















          thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

          – deccc
          Nov 25 '18 at 6:18





          thanks for your help and time, but its still show the same image when i paste code again ... i want to that if i post code 2 time, codes get first 2 images attached to post if i paste code 3 time get 3 images from post. hope you got my point. thanks again

          – deccc
          Nov 25 '18 at 6:18













          is their any possibility to achieve this in wordpress ?

          – deccc
          Nov 25 '18 at 15:24







          is their any possibility to achieve this in wordpress ?

          – deccc
          Nov 25 '18 at 15:24















          sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

          – rheeantz
          Dec 1 '18 at 5:25





          sorry for my bad english.. but i just not clear enough with your question.. or maybe not just me

          – rheeantz
          Dec 1 '18 at 5:25




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460205%2fhow-to-get-next-image-with-my-this-code-from-same-post-wordpress%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python