开发者

use wordpress to list author and author email alternatively

开发者 https://www.devze.com 2022-12-29 06:09 出处:网络
I need to list the authors and their emails alternatively. For example: user1 email_of_user1 user2 email_of_user2

I need to list the authors and their emails alternatively. For example:

  • user1
  • email_of_user1
  • user2
  • email_of_user2

Also, the use开发者_开发知识库r1, user2 should be links to pages where posts are filtered by author. I can use wp_list_authors() function but I can't figure out how to do the alternate user, email thing.


This is exactly what you need. Displays a list of all the authors that have authored at least one post:

<?php
// Displays user name and email from users with at least one post
$blogusers = get_users_of_blog();
if ($blogusers) {
  foreach ($blogusers as $bloguser) {
    $args = array(
    'author' => $bloguser->user_id,
      'showposts' => 1,
      'caller_get_posts' => 1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      $user = get_userdata($bloguser->user_id);
      echo "<li>".$user->user_firstname."</li><li>".$user->user_email."</li>";
    }
  }
}
?>

The second IF ensures that the user has at least one post. If you want to display all the users (having posted something or not) remove these lines:

$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {

}

Hope this helps :)

Adapted code from here: http://wordpress.org/support/topic/274474?replies=2

0

精彩评论

暂无评论...
验证码 换一张
取 消