We launched underscores.me a few hours ago and the overall feedback is great. People seem to love how we automatically pull in contributors using the GitHub API, so I decided to share the code snippet that does that (using WordPress):
function underscoresme_get_contributors() { $transient_key = 'underscoresme_contributors'; $contributors = get_transient( $transient_key ); if ( false !== $contributors ) return $contributors; $response = wp_remote_get( 'https://api.github.com/repos/Automattic/_s/contributors' ); if ( is_wp_error( $response ) ) return array(); $contributors = json_decode( wp_remote_retrieve_body( $response ) ); if ( ! is_array( $contributors ) ) return array(); set_transient( $transient_key, $contributors, 3600 ); return (array) $contributors; }
This function returns an array of contributors to the underscores project (or wherever that URL points to) on GitHub. We cache the results in a transient for better performance too! On the front-end of your site, use the function to grab the array of contributors and print_r
to find out what data is available. Here’s an example that prints out the contributors logins:
foreach ( underscoresme_get_contributors() as $contributor ) { echo $contributor->login; }
Visit the GitHub API docs to learn more.
Since the Github API supports JSONP this would also be doable on the client side. Something like this should work (assumes jQuery): http://pastebin.com/YA1GwfJ0
Cool stuff! Appreciate your comment Joseph!
This is awesome. I decided to take 15 minutes and turn it into a simple WordPress plugin / short code :D
http://ubuntuone.com/74FAndOBRIzGEK7WdEpXAV
I’ll release it shortly.
Looking forward to that, well done!