我在一篇文章中做了图库后的文章缩略图。因此,我列出了所有带有图像类型的帖子附件(使用以下查询),但我想排除帖子缩略图。
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);
我的第一个想法是将缩略图的全尺寸url与每个附件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
));
}
但实际上它还没有起作用。有人知道更简单或更整洁的方法吗?谢谢