List posts by Alpha w/ letter headings
-
Hey Gang,
I have a task that requires an alpha list of posts, with letter headings. I managed to find some resources to help with this, and it works great. I am looking to tweak it though and need some help….
I would like to have the ’empty’ letters be listed/as a subhead… but with not listings below.
Sort of like this:
ABCDEFGH…
A
-A post 1
-A post 2B
-B post 1
-B post 2C
(No listings)D
-D post 1
-D post 2<div class="alpha"> <?php for($i=ord('A');$i<=ord('Z');$i++) { echo '<a class="alphalist" href="#'.chr($i).'">'.chr($i).'</a>'; } ?> </div> <?php $args=array( 'cat' => '-52,-101', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page'=>-1, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $this_char = strtoupper(substr($post->post_title,0,1)); if ($this_char != $last_char) { $last_char = $this_char; echo '<a name="'.$last_char.'"></a><h2>'.$last_char.'</h2>'; } ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br/> <?php echo get_post_meta($post->ID, 'description', true); ?> </p> <?php endwhile; } wp_reset_query(); ?>
Any and all help is much appreciated.
Thanks.
Adam
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘List posts by Alpha w/ letter headings’ is closed to new replies.