I think the problem is the way you use the foreach
with HTML inside. I usually use this way, so try perhaps to modify your code like this :
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
the_content();
// get_template_part( 'template-parts/content','article' );
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
}
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) : ?>
<div class="img-box clearfix detect-inview-2 inview">
<div class="item loaded">
<img src="<?php echo wp_get_attachment_url($attachment->ID); ?>" />
</div>
</div>
<?php endforeach;
}
}