The else
of the $change % 5 == 0
also runs when $change
is a 1
and that is why the first post is displayed twice.
You could fix it by changing
<?php $change++ ?>
<?php endif; ?>
<?php if ( $change % 5 == 0 ) : ?>
to
<?php $change++ ?>
<?php elseif ( $change % 5 == 0 ) : ?>
Or you might also try this one…
$myposts = get_posts(array(...));
foreach($myposts as $change => $post) : setup_postdata($post);
if ( $change == 0 ) : ?>
The first post.
<h3><?php echo 'Post #' . ( $change + 1 ) . ': ' . $post->post_title; ?></h3>
<?php
elseif ( ( $change + 1 ) % 5 == 0 ) : ?>
After every 4th post.
<h3><?php echo 'Post #' . ( $change + 1 ) . ': ' . $post->post_title; ?></h3>
<?php
else : ?>
All other posts.
<h3><?php echo 'Post #' . ( $change + 1 ) . ': ' . $post->post_title; ?></h3>
<?php
endif;
endforeach;
I.e. Simply make use of the $myposts
indexes.