I have the following code that is creating a and A-Z listing of my Posts in a Custom post type. I’d like to somehow create a A-Z menu at the top which links down to its respective anchor. I just can’t seem to get this part to work. Any help much appreciated?
<?php
$args = array(
'post_type' => bha_issues,
//'post_status' => 'bha_issues',
'orderby' => 'title',
'order' => 'ASC',
'caller_get_posts' => 1,
'posts_per_page' => 40,
);
query_posts($args);
if (have_posts()) {
$curr_letter = '';
while (have_posts()) {
the_post();
$this_letter = strtoupper(substr($post->post_title,0,1));
if ($this_letter != $curr_letter) {
echo "<div id='$this_letter' class='hidden'><a name='$this_letter'></a><h2>$this_letter </h2></div>";
$curr_letter = $this_letter;
}
?>
<div id='$this_letter' class='hidden'><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></div>
<?php
}
}
?>
I’ve done something similar before, for a glossary page. My code is below. Hopefully you can extrapolate from this. Note that I’;m using
WP_Query
notquery_posts
, as this is best practice.