0
I need to create an index with Wordpress categories, but do not know how to do. I can list the categories in alphabetical order, but I need to divide them by letters. For example: To ana Amara .... B bob bleating ... C Cristina Claudio ... Does anyone know how I can do it?
Hello friends,
I found a code on the Internet that listed the categories using the initial featured letter. The problem I face with it is that it shows no accented characters, appears a question mark.
<?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();
?>
You are using get_catories() or wp_list_catgories()?
– Gustavo Jantsch
Please show your code. Just [Edit] the question to add details.
– brasofilo
Have you checked the encoding of the files you edited? Check if they are all in utf8
– Ricardo BRGWeb