You need to add the query before the actualy displaying of the div, then you can run your conditional. According to get_posts()
it returns an array, so I’m assuming it returns an empty array if posts aren’t found, thus we can check is it’s not ! empty()
<?php $args = array(
'post_type' => 'attachment',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if( ! empty( $attachments ) ) :
?>
<ul id="slider" class="exhibit-slide">
<?php foreach ( $attachments as $attachment ) {
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $attachment->post_content;
?>
<li>
<div class="exhibit">
<img src="https://wordpress.stackexchange.com/questions/181683/<?php echo wp_get_attachment_url($attachment->ID); ?>" alt="<?php echo $alt; ?>">
</div>
</li>
<?php } ?>
</ul>
<?php endif; ?>