How to List Posts Ordered by Year in WordPress using query_posts

This is a very useful code snippet to use in archive page template.

<?php
query_posts(array('nopaging' => 1, /* we want all posts, so disable paging. Order by date is default */));
$prev_year = null;
if ( have_posts() ) {
   while ( have_posts() ) {
      the_post();
      $this_year = get_the_date('Y');
      if ($prev_year != $this_year) {
          // Year boundary
          if (!is_null($prev_year)) {
             // A list is already open, close it first
             echo '</ul>';
          }
          echo '<h3>' . $this_year . '</h3>';
          echo '<ul>';
      }
      echo '<li>';
      // Print the link to your post here, left as an exercise to the reader
      echo '</li>';
      $prev_year = $this_year;
   }
   echo '</ul>';
}
?>

Source