Wrap/close ‘query’ for a first-letter ordered listing of posts

The problem is that each time you start a new letter, you don’t close the list of the previous one.

Inside your check if ($this_letter != $curr_letter), before the echo, you have to add a </ul> in all cases except when $curr_letter is empty (the first letter).

if ($this_letter != $curr_letter) {
    if('' != $curr_letter){
        echo '</ul></div>';
    }
    echo "<div class="letter_item"><h2>$this_letter</h2><ul>";
    $curr_letter = $this_letter;
}