Skip to content

Instantly share code, notes, and snippets.

@mathetos
Last active January 1, 2016 02:19
Show Gist options
  • Save mathetos/8078647 to your computer and use it in GitHub Desktop.
Save mathetos/8078647 to your computer and use it in GitHub Desktop.
List WP Categories by First Letter
<?php
$args = array(
'orderby' => 'name',
'parent' => 0,
'order' => DESC
);
$categories = get_categories( $args );
$curr_letter = '';
foreach ( $categories as $category ) {
$this_letter = strtoupper(substr($category->name,0,1));
if ($this_letter != $curr_letter) {
echo "<h1>$this_letter</h1><br />";
}
echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>';
$curr_letter = $this_letter;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment