Return to Snippet

Revision: 45471
at May 1, 2011 13:55 by peterbelsky


Updated Code
// 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) {

echo wp_get_attachment_url($image->ID); // attachment url
echo wp_get_attachment_image($image->ID, 'thumbnail'); // thumbnail image
		echo $image->post_title;   // title
		echo $image->post_content; // description
		echo $image->post_excerpt; // caption

	}
}


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') );

	$results = array();

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

Revision: 45470
at May 1, 2011 13:52 by peterbelsky


Initial Code
// 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) {

echo wp_get_attachment_url($image->ID); // attachment url
	}
}


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') );

	$results = array();

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

Initial URL
http://johnford.is/programmatically-pull-attachments-from-wordpress-posts//

Initial Description

                                

Initial Title
Wordpress get gallery images

Initial Tags

                                

Initial Language
PHP