Try to update your second code part with
$count = 1;
foreach( $pages as $post ) {
setup_postdata($post);
// show your post here
if ($count++ % 3 === 0)
echo '<div class="clearfix"></div>';
Try to update your second code part with
$count = 1;
foreach( $pages as $post ) {
setup_postdata($post);
// show your post here
if ($count++ % 3 === 0)
echo '<div class="clearfix"></div>';