Wordpress display an Array under alphabetical letters using PHP

<?php $args = array( 'post_type' => 'post', 'posts_per_page' => - 1, 'orderby' => 'title', 'order' => 'ASC' ); // query $the_query = new WP_Query( $args ); $previous = null; $list = $the_query->posts; foreach ($list as $key => $tag) { $firstLetter = strtoupper(substr($tag->post_title, 0, 1)); if($previous !== $firstLetter) { if($key != 0) { echo '</ol>'; }?> <h3 class="alpha"> <span><?php echo $firstLetter;?></span> </h3> <ol class="tags main"> <?php } ?> <li class="tag"> <a href="<?php echo $tag->guid; ?>"> <strong><?php echo ucfirst($tag->post_title); ?></strong> </a> <span class="perc" style="width: 90px;"></span> </li> <?php if($key == count($list)-1) { echo '</ol>'; } $previous = $firstLetter; } ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.