Return to Snippet

Revision: 51243
at September 19, 2011 11:23 by davebowker


Initial Code
/* Could be nicer. It adds in the <UL> code before and after checking if there are attachements,
	 * but I only want to filter if attachments are bigger than (SIZE), so it may add an <UL> for
	 * attachments that do not meet minimum requirements.
	 */
	$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') );
	if ($attachments > 0) {
		echo '<ul class="post-images">';
	}
	foreach ( $attachments as $attachment_id => $attachment ) {
		$attachment_meta = wp_get_attachment_metadata($attachment_id);
		if ($attachment_meta['width'] == 1280) {
				echo '<li>';
				echo wp_get_attachment_image($attachment->ID, 'full');
				echo '</li>';
			//echo $attachment_meta['width'];
		}
	}
	if ($attachments > 0) {
		echo '</ul>';
	}

Initial URL

                                

Initial Description

                                

Initial Title
Wordpress get attachments

Initial Tags

                                

Initial Language
PHP