WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create an A to Z index of posts in a certain category. This must include a linkable directory of letters ABCDEF .... etc and a list of articles ordered by title grouped by letter.

for example

A first article 
A second article

B first article
B Second aericle 


when some one clicks on the index (ABCDE .....) link him to the letter group....

Any ideas?

share|improve this question
Downvoted, due to the scope of this question. It is at least two (if not more) questions in one, in a "do-work-for-me" format: query posts by category, create letter index, sort posts by first letter. – Chip Bennett Apr 9 '12 at 14:55

It's easy if all posts are shown on the same page, then you can do:

$AZposts = get_posts(array(
    'numberposts'     => -1,
    'post_type'       => 'post',
    'orderby'         => 'title',
    'order'           => 'ASC',
    'category'    => $cat

$current = "";
$nav = "";
$postlist = "";
foreach($AZposts as $AZpost) {
    $firstletter = strtoupper(substr($AZpost->post_title,0,1));
    if($firstletter != $current) {
        $postlist .= "<b><a name='$firstletter'> $firstletter </a></b><br>\n";
        $nav .= "<a href='#$firstletter'> $firstletter </a> ";
        $current = $firstletter;
    $postlist .= $AZpost->post_title . "<br>\n";

print $nav . "<br>" . $postlist;
share|improve this answer
get_permalink( $AZpost->ID ) would be probably useful. Besides that: Nice, canonical answer. +1 :) – toscho Apr 9 '12 at 21:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.