How to Get next image with my this code from same post -(wordpress)
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
add a comment |
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
add a comment |
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
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
php wordpress
edited Nov 25 '18 at 17:45
deccc
asked Nov 24 '18 at 16:36
decccdeccc
276
276
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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