Thanks to the WordPress team for providing such a great platform without any bounds regarding to imaginations. Every functionality that can be imagined can be built with WordPress. The built-in functions of WordPress almost covers all the aspects of web development, but if you couldn’t find a function for your desired functionality you are free to create your own functions such as making additional database tables, querying for any data within custom tables or WordPress default tables.
For beginners it is sometimes difficult to find the specific functions regarding to their desired functionality. Well within WordPress there are two types of functions, those functions which work within WordPress default loop and the others provide the same functionality outside the loop.
Without going into details i am going to show you the quick implementation of displaying the authors list outside the WordPress default loop. For achieving our goal get_users()
is the best function to use. get_users()
function returns an array of user objects which can be traversed for user’s data.
While get_users()
function have several parameters but we will use its two parameters as we are interested in only displaying a list of authors and links to the author’s posts, we will use a few of them.
$usersList = get_users(‘role=author&order=DESC’) ;
This will return all the users with the role of author, you can also get the subscribers by specifying role=subscriber or any users with other roles.
<?php $usersList = get_users('role=author&order=DESC'); foreach($usersList as $c_user) { ?> <a href ="<?php echo get_author_posts_url( $c_user->ID );?>> <?phpecho $c_user->display_name;?> </a></br> <?php } ?>
get_author_posts_url($c_user->ID);
this function requires one parameter which is ID of the author and displays a link to the author’s posts.
The above code is in working state and is tested in plugins and template files. Do comment if you are facing any difficulty implementing this code, I will gladly help and resolve your issues.