How to Group Articles or Posts Alphabetically

To help your site visitors quickly find one or two posts, you can create a list post ordered by date, category, or alphabet. There are tons of tutorials you can find to create this list. But this tutorial is an advance version to list post ordered by alphabet visit for more: http://www.dynamicwp.net/articles-and-tutorials/how-to-group-articles-or-posts-alphabetically/

PHP

<?php
$args=array(
  'orderby' => 'title',
  'order' => 'ASC',
  'posts_per_page'=>-1,
  'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  echo 'Alphabetic index of all ' . count($my_query->posts) . ' 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 '<h2>'.$last_char.'</h2>';
    } ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;
}
wp_reset_query();
?>

Share the love

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. You can use [code][/code] if you want to write codes. Don't spam us :) Thanks!

Advertisement