4

How can I embed Stackexchange reputation scores and badge counts into my Wordpress blog? I want to show on my blog a small table with accounts as rows and columns consisting of rep scores and badge counts. Any ideas on how to do this?

1
  • 1
    Use the API, Luke ;)
    – brasofilo
    Aug 17, 2013 at 23:44

3 Answers 3

11

You could you use User Flair for this:

https://stackoverflow.com/users/flair

1

Here's a testing code I already had for consuming Stack Exchange API:

<?php
/**
 * Plugin Name: Print SE-API Results as Admin Notice
 */

add_action( 'admin_notices', 'b5f_consume_se_api' );

function b5f_consume_se_api() 
{
    $user = '1417894';
    $page_size = '&pagesize=3';
    $order = '&order=desc';
    $sort = '&sort=votes';

    $so = wp_remote_get( 
        'http://api.stackexchange.com/2.1/users/'
        . $user
        . '/answers?site=stackexchange'
        . $page_size . $order . $sort ,     
        array(
            'timeout'     => 120, 
            'httpversion' => '1.1' 
        ) 
    );

    if ( $so['response']['code'] == '200' )
    {
        $so_array = json_decode( $so['body'], true );
        var_dump( $so_array['items'] );
    }
}

This is the URL being consulted and its JSON result. It returns the last 3 answers from the OP, sorted by votes (descending).

Check the docs and adapt everything to suit your needs.

0

Add a text widget your sidebar and paste your flair HTML code in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.