Created
February 22, 2017 20:40
-
-
Save oskaryil/9a8a616d852d345d6df83fabd2030ce6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $posts = get_posts([ | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'post_type' => 'abc' | |
| ]); | |
| $post_index = array_fill_keys( array_merge( [ '#' ], range( 'a', 'z' ), ['å', 'ä', 'ö', ] ), [] ); | |
| foreach( $posts as $post ) { | |
| $first_letter = strtolower( substr( $post->post_title, 0, 1 ) ); | |
| if( is_numeric( $first_letter ) ) { | |
| $post_index[ '#' ][] = $post; | |
| } else { | |
| $post_index[ $first_letter ][] = $post; | |
| } | |
| } | |
| $curent_letter = ''; | |
| echo '<ol type="A">'; | |
| foreach( $post_index as $letter => $letter_list ) { | |
| echo '<li>'; | |
| echo '<ul>'; | |
| foreach( $letter_list as $post ) { | |
| echo '<li>' . $post->post_title . '</li>'; | |
| } | |
| echo '</ul>'; | |
| echo '</li>'; | |
| } | |
| echo '</ol>'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment