meta-author.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * 显示作者meta
  4. * @author KotoriK<https://github.com/KotoriK>
  5. */
  6. function get_author_meta_spans($user_id=false){
  7. global $post;
  8. if (get_the_author()) {
  9. if (function_exists('get_multiple_authors')) {
  10. //plugin_support: PublishPress_Authors
  11. $authors = get_multiple_authors($post, false);
  12. } else {
  13. if (!$user_id) {
  14. global $authordata;
  15. $user_id = isset($authordata->ID) ? $authordata->ID : 0;
  16. } else {
  17. $authordata = get_userdata($user_id);
  18. }
  19. $authors = array($authordata);
  20. }
  21. $returns = array_map(function ($author) {
  22. $author_post_url=get_author_posts_url($author->ID);
  23. return '<span class="meta-author">' .
  24. '<a href="' . $author_post_url . '">' .
  25. get_avatar($author,16,'',$author->display_name,array("class"=>"avatar")).
  26. '</a>' .
  27. '<a rel="author" title="' . $author->display_name . '" href="' . $author_post_url . '">'
  28. . $author->display_name .
  29. '</a>' .
  30. '</span>';
  31. }, $authors);
  32. echo join('', $returns);
  33. }
  34. }
  35. ?>