IGZones provides a unique service where in you can get the live game ratings. They can be either your ratings or your clan’s. I wanted to display my n00b rating here on this site in the sidebar. Its very easy you just have to write a small piece of code and you are off.

First of all, go here » Rating Services and familiarise yourself with the type of requests and the variables.

Now, to add the ratings to the sidebar, there are two ways. One, You can directly edit the template and add the code in the sidebar.php. This is the simplest way. There is a problem with this though, you cannot place the widget at any place you like, you can only add it either at the top or the bottom of the dynamic sidebar which is controlled by wordpress.

The other and a better way is to add the a widget with your code via wordpress so that you have full control over its position. WordPress has a Text/Html widget but it doens’t parse PHP on the fly, so download and install this plugin » PHP Code Widget. This plugin allows us to insert and execute php code in a widget. After installing the plugin, in the widgets page, a “PHP Code” widget will appear, add it to your sidebar, click on edit and enter the php code. Save and refresh. The code will now be executed.

Coming to the code to display the ratings, its similar to the example on the Rating Services page. Its simpler if you are displaying the ratings of just one user. First, we have to prepare the request URL. If your user name is tHeSiD and you want the ratings from the AoC Random Map ladder, the URL will be

http://www.igzones.com/ratingservices?ladder=AoCRM&player=tHeSiD

The format would be

http://www.igzones.com/ratingservices?ladder=<ladder>&player=<username without clan tag>

The response to this will be a Comma Separated Values string

example : 114752,tHeSiD,1622,56,53,0,1,AoCRM,1233541,2008-08-27 19:14:43

The values are in the following order

User ID, User name, Rating, Wins, Losses, Incomplete, Streak, Ladder, Last Match, Last Match Date & Time

Rest is just to explode this string into an array and get the values from it. The code will explain this better.

This code is for single user only. Prepare your Request URL and replace the URL in the code with yours.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
	$igz_site = fopen("http://www.igzones.com/ratingservices?ladder=AoCRM&player=tHeSiD", "r");
	$ratingservices_page = fread($igz_site, filesize($igz_site));
	fclose($igz_site);
	$igz = explode(",", $ratingservices_page);
		$userid = $igz[0];
		$name = $igz[1];
		$rating = $igz[2];
		$wins = $igz[3];
		$losses = $igz[4];
		$inc = $igz[5];
		$streak = $igz[6];
		$ladder = $igz[7];
		$lastmatch = $igz[8];
		$date = $igz[9];
 
	$data = '<ul>
		<li>Tag : <a href="http://www.igzones.com/user/'.$userid.'">'.$name.'</a></li>
		<li>Ladder : '.$ladder.'</li>
		<li>Rating : '.$rating.'</li>
		<li>Wins : '.$wins.'</li>
		<li>Losses : '.$losses.'</li>
		<li>Streak : '.$streak.'</li>
		<li>Last match : <a href="http://www.igzones.com/matches/'.$lastmatch.'" target="_blank">'.$date.'</a></li></ul>';
	echo '<a align="center" href="http://www.igzones.com" target="_blank"><img class="igzimg" src="http://www.igzones.com/images/microbanner.png"  border="0" alt="Age of Empires IGZones"></a><br/>';
	echo $data;
?>

If in any case you have a problem with the filesize() function, just replace filesize($igz_site) with a numerical value. I recommend 75. so line 3 should be

1
$ratingservices_page = fread($igz_site,75);

Save the widget and refresh your site. Your ratings will now be visible in the sidebar.

Bookmark and Share