Created
November 28, 2015 05:10
-
-
Save soggybag/e7d815d01b49e7d1a61c to your computer and use it in GitHub Desktop.
WordPress, simple function fetches all images uploaded to the current post.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This function fetches all of the images uloaded to the current post. | |
Pass in the image size, and the number of images to return. | |
Use this function in the loop. | |
*/ | |
function get_images_in_current_post( $size="thumbnail", $num=-1 ) { | |
global $post; | |
$attachments = get_posts( array("numberposts" => $num, | |
"post_type" => "attachment", | |
"post_parent" => $post->ID, | |
"orderby" => "name" ) ); | |
// Loop through array | |
// [img, img, img ... ] | |
foreach( $attachments as $attachment ) { | |
$img = wp_get_attachment_image( $attachment->ID, $size ); | |
echo "<div class='post-img'>$img</div>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment