Skip to content

Instantly share code, notes, and snippets.

@corpsefilth
Created September 18, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpsefilth/73434038eff303f0ec75 to your computer and use it in GitHub Desktop.
Save corpsefilth/73434038eff303f0ec75 to your computer and use it in GitHub Desktop.
display list of attached images of a page or post excluding featured image
<?php
//get featured image ID
$thumb_ID = get_post_thumbnail_id( $post->ID );
//attachement loop - with exclude argument for featured image
$args = array(
'orderby' => 'menu_order',
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'post_mime_type' => 'image',
'post_status' => null,
'posts_per_page' => -1,
'exclude' => $thumb_ID
);
$attachments = get_posts($args);
?>
<?php
//Goes inside loop
function getAttachedImagesButThumbnail() {
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
foreach( $images as $imageID => $image ) {
if ( $image->ID == $post_thumbnail_id) {
unset ($images[$imageID]);
} else {
$out .= wp_get_attachment_image($imageID, array(285,285), false);
}
}
return $out;
}
?>
<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
) );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
$thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );
echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';
}
}
}
?>
<?php
$thumb_ID = get_post_thumbnail_id( $post->ID );
echo $thumb_ID;
$gall = '[gallery exclude="'.$thumb_ID.'"]';
echo $gall;
echo do_shortcode($gall);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment