well you’ve to change code in loop
for example currently now loop is like
<?php if(have_post) : while(yourquery): the_post : <div>the_title</div><div>the_content</div> endwhile; endif;
Then Just Add this line also
<?php if(have_post) : while(yourquery): the_post <a name="$i"><div>the_title</div><div>the_content</div></a> endwhile; endif;