I need to create an index with the Wordpress categories, but I do not know how to do it. I can list the categories in alphabetical order, but I need to divide them by letters. For example: THE Ana will love .... B bob Bernabe ... W Cristina Claudio ... Does anyone know how I can do this?
Hello friends,
I found a code on the internet that listed the categories using the highlighted initial letter. The problem I face with it is that it does not show accented characters, an interrogation appears.
<?php
$param_type = 'category__in'; // e.g. tag__in, category__in
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
if ($categories) {
$first_letter = null;
$group_per_column = 2;
$i = 0;
$ic = 0;
foreach ($categories as $category) {
$category_letter = strtoupper(substr($category->name, 0, 1));
if ($first_letter != $category_letter) {
if ($i % $group_per_column == 0) {
if ($first_letter != '')
echo '</ul></li></ul></div>' . $parent_ul;
$first_letter = $category_letter;
$i += 1;
$ic += 1;
echo "<div class=\"wrap column_$ic\"><ul class=\"category_list\"><li class=\"$category_letter\"><h2> - $i $category_letter - </h2>";
echo '<ul>';
} else {
if ($first_letter != '')
echo '</ul></li></ul>' . $parent_ul;
$first_letter = $category_letter;
$i += 1;
echo "<ul class=\"category_list\"><li class=\"$category_letter\"><h2> - $i $category_letter - </h2>";
echo '<ul>';
}
}
$args = array(
"$param_type" => $category->id,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'name',
'order' => 'ASC'
);
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo '<li><a href="' . get_category_link($category->term_id) . '" title="' . $category->name . '">' . $category->name . '</a></li>';
}
}
echo '</ul></li></ul></div>';
}
wp_reset_query();
?>