forked from skryvets/Wordpress-Bootstrap-Dictionary-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphabet.php
32 lines (27 loc) · 997 Bytes
/
alphabet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
//String split into array of chars. Unicode support.
function str_split_unicode( $str, $l = 0 ) {
if ( $l > 0 ) {
$ret = array();
$len = mb_strlen( $str, "UTF-8" );
for ( $i = 0; $i < $len; $i += $l ) {
$ret[] = mb_substr( $str, $i, $l, "UTF-8" );
}
return $ret;
}
return preg_split( "//u", $str, - 1, PREG_SPLIT_NO_EMPTY );
}
$alphabet = array( 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'І', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ў', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Ы', 'Ь', 'Э', 'Ю', 'Я' );
//First letters from the titles
$letters = array();
query_posts( 'posts_per_page=500&order=asc' );
//Finding first letters from alphabet
if ( have_posts() ) : while ( have_posts() ) : the_post();
$current_title = the_title( '', '', false );
$title_arr = str_split_unicode( $current_title );
if ( ! in_array( $title_arr [0], $letters ) ) {
array_push( $letters, $title_arr [0] );
}
endwhile;
endif;
?>