Title: Alphabetical post list
Last modified: August 20, 2016

---

# Alphabetical post list

 *  Resolved [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/alphabetical-post-list/)
 * Hi There
 * I’m attempting to list posts alphabetically from a cat page, which I’ve got working
   using MichaelH’s great piece of code from here:
 * [http://wordpress.org/support/topic/first-letter-posts](http://wordpress.org/support/topic/first-letter-posts)
 * And using this code above `
    $alphabet = range(‘A’, ‘Z’); foreach ($alphabet 
   as $letter) { echo ‘<a href=”?letter=’ . $letter . ‘”>’ . $letter . ‘</a>’; }
   $_GET[“letter”];`
 * to output an a-z list which links to the same page telling Michaels code which
   letter to display.
 * My question is instead of outputting a full alphabetical list is it possible 
   to list it as such ‘A – I’ ‘J – Q’ ‘R – Z’ ?
 * Any pointers appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/alphabetical-post-list/#post-2612132)
 * Hmmm… still scratching my head with this one. Let me narrow the question, is 
   it possible to “order by” ‘range’?:
 *     ```
       $postids=$wpdb->get_col($wpdb->prepare("
       SELECT      ID
       FROM        $wpdb->posts
       WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
       ORDER BY    $wpdb->posts.post_title",range ('A' , 'I')));
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/alphabetical-post-list/#post-2612277)
 * Ok getting nearer. I’ve found a way to display all post titles with multiple 
   first letters a-i.
 * I just need to create three links and pass that ‘variable’ so it displays posts
   with either ‘a-i’, j-q’, ‘r-z’ and can’t quite get it but feel i’m really close.
   Any help really appreciated.
 *     ```
       <a href="?range=a_i">A-I</a>
       <a href="?range=j_q">J-Q</a>
       <a href="?range=r_z">R-Z</a>
   
       <?php
       $a_i = "'A','B','C','D','E','F','G','H','I'";
       $j_q = "'J','K','L','M','N','O','P','Q'";
       $r_z = "'R','S','T','U','V','W','X','Y','Z'";
   
       $range=$_GET['range'];
   
       $postids=$wpdb->get_col($wpdb->prepare("
       SELECT      ID
       FROM        $wpdb->posts
       WHERE       SUBSTR($wpdb->posts.post_title,1,1) IN ($range)
       ORDER BY    $wpdb->posts.post_title"));
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/alphabetical-post-list/#post-2612284)
 * Ahhh….. Gave up and used ‘if else’
 *     ```
       <a href="?range=a_i">A-I</a>
       <a href="?range=j_q">J-Q</a>
       <a href="?range=r_z">R-Z</a>
   
       <?php $range = $_GET['range'] ?>
   
       <?php if ($range == 'a_i') { ?>
   
       // show list  A - I
   
       <?php } elseif ($range == 'j_q') { ?>
   
       // show list  A - I
       ```
   
 * So ugly it needs a bag but my brain hurts.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Alphabetical post list’ is closed to new replies.

## Tags

 * [alphabetical](https://wordpress.org/support/topic-tag/alphabetical/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 1 participant
 * Last reply from: [formica](https://wordpress.org/support/users/formica/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/alphabetical-post-list/#post-2612284)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
