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?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Chernoff
  • 2,494
  • 2
  • 20
  • 24

3 Answers3

11

You could you use User Flair for this:

https://stackoverflow.com/users/flair

Community
  • 1
  • 1
Brian
  • 6,910
  • 8
  • 44
  • 82
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.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
0

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

Community
  • 1
  • 1
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58