我有一个设置,在那里我想实现我有一个产品的大图(张贴图像),然后下面是其他缩略图列表,可以在灯箱中打开。我这样做是通过以适当的大尺寸查询帖子图像,然后通过WP\\u Query post类型查询附件图像。但是,问题是,查询也会得到帖子缩略图,而不仅仅是贴在帖子上的图像。这是代码
<div class="product-img">
<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
<?php // get fullimage
$thumb_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $thumb_id,\'full\' ); ?>
<a href="<?php echo $image[0]; ?>" title="<?php the_title(); ?>" rel="lightbox">
<?php the_post_thumbnail( \'large\' ); // large image for the single post ?>
</a>
<?php endif; ?>
<div class="other-images">
<?php /* QUery attached images */
$images_query_args = array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => \'image\',
\'post_parent\' => $post->ID
);
$images_query = new WP_Query( $images_query_args );
if ( $images_query->have_posts() ) : while ( $images_query->have_posts() ) : $images_query->the_post();
?>
<a href="<?php echo wp_get_attachment_image_url( get_the_ID(), \'large\' ); ?>" title="<?php the_title(); ?>" rel="lightbox">
<?php // Output the attachment image
echo wp_get_attachment_image( get_the_ID(), \'thumbnail\' ); ?>
</a>
<?php
endwhile; endif;
wp_reset_postdata();
?>
</div>
如何使image\\u查询不显示post图像,而只显示其他图像?或者,如果有一个插件可以比原生WP更好地处理附加的库(例如自定义排序顺序,更好地可视化附加的图像),我也有兴趣在必要时重新编写代码。对于编辑来说,重要的是这些图库是按帖子排列的,而不是通过诸如NextCellent这样的短代码分开的
最合适的回答,由SO网友:Milo 整理而成
您可以使用post__not_in
要按ID排除图像,请执行以下操作:
$images_query_args = array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => \'image\',
\'post_parent\' => $post->ID,
\'post__not_in\' => array(get_post_thumbnail_id())
);