Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created December 7, 2010 18:35
Show Gist options
  • Save iammerrick/732190 to your computer and use it in GitHub Desktop.
Save iammerrick/732190 to your computer and use it in GitHub Desktop.
<?php if ( ! have_posts() ) : ?>
<p>We couldn't find any resources.</p>
<?php
endif;
$in_use = array();
?>
<ul class="resources">
<?php while ( have_posts() ) : the_post(); ?>
<?php
$first_letter = substr(get_the_title(), 0, 1);
if(in_array($first_letter, $in_use)):
?>
<li><a href="#"><?php the_title(); ?></a></li>
<?php
else:
array_push($in_use, $first_letter);
?>
</ul>
<h2><?php echo $first_letter; ?></h2>
<ul class="resources">
<li><a href="#"><?php the_title(); ?></a></li>
<?php
endif;
?>
<?php endwhile; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment