This is worth a bump. I just put this to work and it's brilliant. I don't completely understand the MySQL stuff (I'm a PHP newb), but I did hack this code a bit so that the category is automatically pulled from url. I figured the code might be worth a repost since it's a little mangled up above anyway (this may take two posts -- I'm still new at posting code myself):
<ol class="alphabet">
<?php
$tempstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for ( $i = 0; $i < strlen ( $tempstr ); $i++ ) {
$l = substr ( $tempstr, $i, 1 );
echo "<li";
if ( $_GET['letter'] == $l ) { echo " class="active""; }
echo "><a href="index.php?cat=".$_GET['cat']."&letter=".$l."">".$l."</a></li>";
} ?>
</ol>
<div class="someclass">
<ul class="letter">
<?php
global $wpdb, $tableposts, $tablepost2cat;
$letter = $_GET['letter'];
$category = $_GET['cat'];
if( $letter == '0' ) {
$query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE left( post_title, 1 ) BETWEEN '0' AND '9' AND (post_id = ID AND category_id = '".$category."') ORDER BY post_title ASC";
} elseif( $letter == 'all' ) {
$query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE post_id = ID AND category_id = '".$category."' ORDER BY post_title ASC";
} else {
$query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE ( left( post_title, 1 ) = '".$letter."' OR left( post_title, 5 ) = 'the ".$letter."') AND (post_id = ID AND category_id = '".$category."' ) ORDER BY post_title ASC";
}
$results = $wpdb->get_results ( $query );
// display selection
if ($results) {
foreach ($results as $result) {
echo "<li><a href="#">".stripslashes($result->post_title)."</a></li>";
}
} else {
echo 'No articles found.';
} ?>
</ul>
</div>