您可以使用Walker将输出自定义为按字母拆分。从这里开始,CSS就可以实现列格式。
快速挑战Walker:
class Walker_Alphabetized_Category extends Walker_Category {
var $letter = \'\';
function start_el(&$output, $category, $depth, $args) {
$current_letter = strtoupper(substr($category->name,0,1));
if( empty($this->letter) ) {
$this->letter = $current_letter;
$output .= "<li>{$current_letter}<ul>";
}
elseif( $this->letter != $current_letter ) {
$output .= "</ul></li>";
$this->letter = $current_letter;
$output .= "<li>{$current_letter}<ul>";
}
parent::start_el(&$output, $category, $depth, $args);
}
}
echo \'<ul>\';
wp_list_categories(array(
\'hierarchical\' => false,
\'orderby\' => \'name\',
\'title_li\' => \'\',
\'walker\' => new Walker_Alphabetized_Category(),
));
echo \'</ul>\';