Created
October 28, 2011 06:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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