Loop increase in while loop not working

You’re reassigning 1 to $i on every loop:

if ( $i = 1) { 

This should be

if ( $i == 1) { 

or even

if ( $i === 1) { 

which will also compare the post type, which is best practice.

In PHP, = is assignment, == is comparison: