Skip to content

Commit 28280d4

Browse files
author
Dale Nguyen
authored
Merge pull request #21 from wajidalitabassum143/master
Add snippet to show a list of all authors #hacktoberfest22
2 parents 16203d3 + 7b0fd02 commit 28280d4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Below is the list of useful WordPress Snippets that you can use when developing
1919
+ [Remove inline styling from tag cloud](https://github.com/dalenguyen/wordpress-snippets/blob/master/src/remove_inline_styling_from_tag_cloud.php)
2020
+ [Show related posts on single](https://github.com/wajidalitabassum143/wordpress-snippets/blob/master/src/show_related_posts_on_single.php)
2121
+ [Shortcode: show popular blog posts based on cat](https://github.com/wajidalitabassum143/wordpress-snippets/blob/master/src/show_popular_blog_posts_based_on_cat_shortcode.php)
22+
+ [List all authors of a blog grouped by first name with a single letter as a header character](https://github.com/wajidalitabassum143/wordpress-snippets/blob/master/src/list_authors_alphabetically.php)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
//* List all authors of a blog grouped by first name with a single letter as a header character.
4+
5+
function list_authors_alphabetically() {
6+
7+
$users = get_users( 'orderby=user_login&role=author' );
8+
9+
$first_letter = '';
10+
11+
foreach( $users as $user ) {
12+
13+
$space = strpos( $user->user_login, ' ' );
14+
$letter = substr( $user->user_login, 0, 1 );
15+
$letter = strtoupper( $letter );
16+
17+
if ( $letter != $first_letter ) {
18+
19+
$first_letter = $letter;
20+
21+
echo "<h4 id='ft_contrib_alphaletter_$first_letter'> $first_letter </h4>";
22+
23+
}
24+
25+
echo '<a href="' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . $user->display_name . '">' . $user->display_name . '</a>';
26+
27+
echo "<br>";
28+
}
29+
30+
}

0 commit comments

Comments
 (0)