Another option if you don’t want to hard-code the alphabet links (i.e., if no posts start with a letter, then that letter is not shown in pagination at all).
// Always show pagination
// First, grab all posts.
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'homeless',
'orderby' => 'title',
'order' => 'ASC'
));
// Next, grab the first letter of each title.
$firstLetters = array();
foreach($posts as $post) {
$title = $post->post_title;
$startingLetter = substr($title, 0, 1);
$dupeFirstLetters[] = $startingLetter;
// Remove duplicates
$firstLetters = array_unique($dupeFirstLetters);
// Alphabetize
sort($firstLetters);
}
foreach($firstLetters as $letter) {
// Output the letter pagination, only for letters that have posts
echo "<a href=\"?letter=$letter\">$letter</a>";
}
// If there is a request for a specific "letter" in the query string
if(!empty($_GET['letter'])) {
$letter = $_GET['letter'];
}
// Else, default to showing the first found letter
// i.e. A if there are any post titles starting with A
else {
$letter = $firstLetters[0];
}
// Finally, run a custom query to display the posts - see Max's link #1 above for specifics
You can then run the query to pull just the posts starting with that letter, and display them however you want.