Display Custom Post Types Glossary

I have a custom Post Type called as “Book” and I want to display a “Glossary” on my home page like – ‘A B C D E F…’ so that they can be linked to a page on my website as – http://example.com/c-books or http://example.com/b-books for “C” & “B” letters respectively. I have seen this link but I am not sure if this is something that will help me create this.

Any help will be appreciated or any references to some plugin that can help me achieve the same.

Solutions Collecting From Web of "Display Custom Post Types Glossary"

I used this code to create a glossary for a custom pos called “store”.
So you can use it just replacing the “store” by “book”. Put this code in the loop of the page template you will be using for the glossary.


$last_char = '';
$args=array(
  'orderby' => 'title',
  'order' => 'ASC',
  'posts_per_page'=>-1,
  'post_type' => 'store'
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  echo count($my_query->posts) . ' магазинов';
  echo '';
  while ($my_query->have_posts()) : $my_query->the_post();

$this_char = mb_strtoupper(mb_substr($post->post_title,0,1));
if ($this_char != $last_char) {
  $last_char = $this_char;
  echo '<a href="#'.$last_char.'">'.$last_char.'</a>';
}

endwhile;
while ($my_query->have_posts()) : $my_query->the_post();
$this_char = mb_strtoupper(mb_substr($post->post_title,0,1));
if ($this_char != $last_char) {
$last_char = $this_char;
echo ''.$last_char.'';
}
echo ''. get_the_title() .'';

endwhile;
}
wp_reset_query();