+7 982 100 5 999

Вывести Букву и записи к ней в алфавитном порядке

<?php $posts = get_posts('post_type=logos & orderby=title&posts_per_page=10');
foreach( $posts as $k => $post ){ ?> 
<ul>
<?php $fl = get_first_letter( $post->post_title );
$prev_fl = isset( $posts[ ($k-1) ] ) ? get_first_letter( $posts[ ($k-1) ]->post_title ) : ''; ?>
    <div class="letter"><?php	echo $fl; ?></div>

    <?php if( $prev_fl !== $fl ) ?>
    <li><?php echo $post->post_title; ?></li>
</ul>
<?php } ?>
<?php function get_first_letter( $str ){
    return mb_substr($str, 0, 1, 'utf-8');
} ?>