{"id":14,"date":"2010-09-09T18:35:31","date_gmt":"2010-09-09T22:35:31","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/mypain\/?p=14"},"modified":"2014-05-07T15:31:59","modified_gmt":"2014-05-07T19:31:59","slug":"wordpress-author-list-with-gravatars-but-for-wpmu","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/mypain\/2010\/09\/09\/wordpress-author-list-with-gravatars-but-for-wpmu\/","title":{"rendered":"WordPress author list with gravatars &#8211; but for WPMU"},"content":{"rendered":"<p>So this seemed really easy, but apparently it was not, or I guess I would not be writing about it here.\u00a0 Ok, here is the deal, I wanted a full list of all the authors on one particular blog.\u00a0 I wanted them all on one page and listed out with links to their blog posts.\u00a0 I wanted them all to have images next to their names.  The standard way to do this seems to be to list out all the user names on your blog, since hey, no harm here, we are only running one blog.<\/p>\n<p>Enter WPMU.\u00a0 We are not running just one blog, we are running hundreds and have thousands of users.\u00a0 Listing out all the users via a SQL query would be a huge list, not to mention not at all representative of who is an author on this particular blog.\u00a0 I did some looking around on the <a title=\"Wordpress Codex\" href=\"http:\/\/codex.wordpress.org\" target=\"_blank\">wordpress codex<\/a> and found a couple of functions that I thought could be helpful.\u00a0 The first one that came up was <a title=\"Wordpress function wp_list_authors\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wp_list_authors\" target=\"_blank\">wp_list_authors<\/a>.\u00a0 This function just lists out all the authors for a particular blog &#8211; particularly helpful for WPMU sites.<\/p>\n<p>Now the problem with wp_list_authors is that it just outputs the list of authors as a chunk of links, so you have to chop it up somehow since its not in the loop &#8211; yeah, we are doing all this outside of the loop.\u00a0 The second issue is that this is all that it puts out &#8211; links to the author archive page.\u00a0 No ids, no emails, nothing &#8211; its not like <a title=\"Wordpress function the_author_meta\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/the_author_meta\" target=\"_blank\">the_author_meta<\/a> which gives you all kinds of nice stuff.<\/p>\n<p>Ok, but at least we have something we can hack up, so I started in on it and this is what I came up with.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$allAuthorNames = explode(',',wp_list_authors('style=0&amp;amp;show_fullname=1&amp;amp;hide_empty=0&amp;amp;echo=0'));\r\nforeach ( $allAuthorNames as $oneAuthorName ) { ?&gt;\r\n  &lt;li&gt;\r\n  &lt;?php\r\n  $oneAuthorArray = explode(&quot; &quot;,$oneAuthorName);\r\n  if (count($oneAuthorArray) &gt; 1) {\r\n    $oneAuthorLink = explode(&quot;\/&quot;,$oneAuthorArray&#x5B;2]);\r\n    end($oneAuthorLink);\r\n    $userData = get_userdatabylogin(prev($oneAuthorLink));\r\n  } else {\r\n    $userData = array(&quot;user_email&quot; =&gt; &quot;None&quot;);\r\n  }\r\necho get_avatar($userData-&gt;user_email,$size='96',$default='');\r\n?&gt;\r\n&lt;?php echo ($oneAuthorName); ?&gt;\r\n&lt;\/li&gt;\r\n&lt;?php } ?&gt;\r\n<\/pre>\n<p>Pardon my PHP, it sucks, but in any case it gets it done here at least.<\/p>\n<p>Notice the nice function that gets it done?  Oddly, there is not much documentation to the <a title=\"Wordpress function get_userdatabylogin\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/get_userdatabylogin\" target=\"_blank\">get_userdatabylogin<\/a> function, but its a nice one.\u00a0 Tie together wp_list_authors with get_userdatabylogin and you can get even more info than you can get from the_author_meta.<\/p>\n<p>Now this code is by no means the finished product, but it does work and it is a nice way to get a full list of everything that the author has in their profile in the DB.  At the moment I just used it to get the email address of the author I was iterating over, but the function dumps out the entire user DB row object.  A bit dangerous I suspect, but useful.<\/p>\n<p>Happy coding,\u00a0 hope this saves you a bit of time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So this seemed really easy, but apparently it was not, or I guess I would not be writing about it here.\u00a0 Ok, here is the deal, I wanted a full list of all the authors on one particular blog.\u00a0 I wanted them all on one page and listed out with links to their blog posts.\u00a0 [&hellip;]<\/p>\n","protected":false},"author":758,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,3163,19259],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-code","category-php","category-wpmu","post-preview"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/users\/758"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":20,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/posts\/14\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/mypain\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}