Skip to content

Instantly share code, notes, and snippets.

@NateJacobs
Created October 28, 2011 06:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NateJacobs/1321741 to your computer and use it in GitHub Desktop.
Save NateJacobs/1321741 to your computer and use it in GitHub Desktop.
WordPress Function: List all authors of a blog grouped by first name with a single letter as a header character.
<?php
/**
* List Users Alphabetically
*
* Create a list of all authors of a WordPress blog.
* Names are grouped by first name with a single letter
* as a header character.
*
* Call the function with <?php ngtj_list_users_alphabetically(); ?>
* where you want the list to appear.
*
* @author Nate Jacobs
* @link https://gist.github.com/1321741
*/
function ngtj_list_users_alphabetically()
{
$users = get_users( 'orderby=display_name&role=author' );
$first_letter = '';
foreach( $users as $user )
{
$space = strpos( $user->display_name, ' ' );
$letter = substr( $user->display_name, 0, 1 );
if ( $letter != $first_letter )
{
$first_letter = $letter;
echo "<strong>$first_letter</strong>";
echo "<br>";
}
echo $user->display_name;
echo "<br>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment