/ Published in: PHP
URL: http://johnford.is/programmatically-pull-attachments-from-wordpress-posts//
Expand |
Embed | Plain Text
// GET THE PATHS // IN FUNCTIONS: // get all of the images attached to the current post function aldenta_get_images($size = 'thumbnail') { global $post; return get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); } // IN PAGE if ($images = aldenta_get_images()) { foreach ($images as $image) { } } GET THE IMAGES // IN FUNCTIONS // get all of the images attached to the current post function aldenta_get_images($size = 'thumbnail') { global $post; $photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); if ($photos) { foreach ($photos as $photo) { // get the correct image html for the selected size $results[] = wp_get_attachment_image($photo->ID, $size); } } return $results; } // IN PAGE $photos = aldenta_get_images('full'); if ($photos) { foreach ($photos as $photo) { echo "$photo<br />"; } }
Comments
Subscribe to comments
You need to login to post a comment.

Thanks very much for this code snippet