I would avoid this kind of excess indentation at all costs, however this should work although I haven’t tested it. Please let me know if there are syntax errors so that I can correct them.
<!-- first loop : 1 post -->
<?php
if ( have_posts() ):
the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/31361/<?php the_permalink() ?>" rel="bookmark" title="" ><?php the_title(); ?></a>
<!-- second loop : 2 posts -->
<?php
if ( have_posts() ):
$count = 0;
while ( have_posts() ):
the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/31361/<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
<!-- third loop : 5 posts -->
<?php
if ( ++$count == 2 and have_posts() ):
$count = 0;
while ( have_posts() ):
the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/31361/<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
<!-- fourth loop : the rest -->
<?php
if ( ++$count == 5 and have_posts() ):
while ( have_posts() ):
the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/31361/<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
<?php
endwhile;
else: // fourth loop has no posts
endif;
endwhile;
else: // third loop has no posts
endif;
endwhile;
else: // second loop has no posts
endif;
else: // first loop has no posts
endif;
?>
A more elegant solution would be something along these lines:
<?php
$page_counts = array(1, 2, 5, 9999);
foreach ($page_counts as $iteration => $max_count) {
$count = $max_count;
while ( have_posts() and $count-- ) {
the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/31361/<?php the_permalink() ?>" title="" ><?php the_title(); ?></a>
<?php
} else break; // No more posts to grab!
}
?>
Again, untested, may contain a mismatching brace or something.