You can do this, and it isn’t that hard though could be a lot of work for the server. The code, a bit simplified, should look something like this:
$cposts = wp_list_pluck($wp_query->posts,'ID');
// var_dump($cposts); // debug
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'order' => 'DESC',
'posts__in' => $cposts
);
// var_dump($args); // debug
$query_images = new WP_Query( $args );
// var_dump($query_images->posts); // debug
if ($query_images->have_posts()) {
while ($query_images->have_posts()) {
$query_images->the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/116809/<?php echo get_permalink($post->post_parent); ?>" title="<?php the_title_attribute(); ?>" ><?php echo wp_get_attachment_image(get_the_ID(), $size); ?></a><?php
}
}
That code assumes that you are on a category archive and used the results already returned by the main query. This means that you will only get the images associated with the current page of paginated results.