Skip to content

Instantly share code, notes, and snippets.

@miklb
Created March 26, 2012 14:00
Show Gist options
  • Save miklb/2205266 to your computer and use it in GitHub Desktop.
Save miklb/2205266 to your computer and use it in GitHub Desktop.
grab all image attachments minus post_thumbnail in WordPress
function kkf_get_images($overrides = '', $exclude_thumbnail = false)
{
return get_posts(wp_parse_args($overrides, array(
'numberposts' => -1,
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'exclude' => $exclude_thumbnail ? array(get_post_thumbnail_id()) : array(),
'orderby' => 'menu_order ID'
)));
}
<?php $photos = kkf_get_images('numberposts=-1', true); ?>
<?php if ( $photos ) {
foreach ($photos as $photo) { ?>
<img src="<?php echo wp_get_attachment_url($photo->ID); ?>" alt="" height="540" width="935"/>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment