I'm doing gallery in a single post after the post thumbnail. So I list all the post attachment with the image type (with the following query) but I want to exclude the post thumbnail.
global $post;
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_parent' => $post->ID
);
$images = get_posts($args);
My first idea was to compare the thumbnail full size url with each attachment src.
$large_image_url = "";
if ( has_post_thumbnail() ):
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
$large_image_url = parse_url($large_image_url[0], PHP_URL_PATH);
/*
* [...]
*/
global $post;
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_parent' => $post->ID
);
$images = get_posts($args);
foreach($images as $image){
$big_array = image_downsize( $image->ID, 'full' );
$img_url = $big_array[0];
if(!empty($large_image_url) && $large_image_url == $img_url){
continue;
}
array_push($gallery, array(
'dirname' => dirname($img_url),
'filepath' => parse_url($img_url, PHP_URL_PATH),
'ID' => $image->ID
));
}
But actually it doesn't work yet. Does someone know a simpler or neater way to do so ? Thanks
WP_DEBUG
totrue
in the wp-config.php) also helps. Btw: Yourif( has_post_thumbnail() ) :
has noendif;
- where should that be?