foreach ($categories as $category) {
$l2 = mb_substr($category->description, 0, 1, 'utf-8');
if ($l1 != $l2) {
$l1 = $l2;
echo "<h2>$l1</h2>";
}
echo '<a href="' . get_category_link($category->term_id) . '">' . $category->description . '</a>';
}
$prev_char = null;
foreach ($categories as $category) {
$curr_char = mb_substr($category->description, 0, 1, 'utf-8');
if ($curr_char != $prev_char) {
if (isset($prev_char)) {
echo "</ul>\n";
echo "</section>\n";
}
$prev_char = $curr_char;
echo "<section>\n";
echo "<h2>$curr_char</h2>\n";
echo "<ul>\n";
}
echo '<li><a href="' . get_category_link($category->term_id) . '">' . $category->description . '</a></li>';
}
echo "</ul>\n";
echo "</section>\n";