Create a WordPress MochiAds Leaderboards Widget
Some time ago I blogged about Showing MochiAds leaderboards in any Flash movie or web page with a script made by myself that displayed MochiAds leaderboards on your site.
Yesterday MochiAds guys released a widget that accepts a game slug and partner ID and will display all the available leaderboards for the given game. The partner ID will constrain the widget to showing only scores from your site if you choose to do so. The widget is a Flash .SWF that can be embedded on any HTML page on your site.
In the official docs page there is an example using swfobject library but there is a much simpler way to embed scores… here it is:
|
1 |
<embed src="http://dev.mochiads.com/static/pub/swf/LeaderboardWidget.swf?game=ballbalance" allowscriptaccess="always" menu="false" quality="high" width="400" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed> |
Just replace ballbalance with the game slug you want to display highscores.
Width and height have minimum values of 230 and 200 pixels, and the score table will adjust according to size.
Here it is an example of a leaderboard with 400×400
And this is the tiniest one…
… that looks perfect to be embedded in a blog
Let’s create the WP widget!
Before continuing, I suggest you to read How to create a WordPress Widget if you don’t have experience with WP widgets.
The new widget is made this way (don’t worry, I’ll explain how to do it during one of next tutorials)
|
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?php /* Plugin Name: MochiScores Plugin URI: http://www.emanueleferonato.com/ Description: Displays MochiAds leaderboard in your WP blog!! Author: Emanuele Feronato Version: 1 Author URI: http://www.emanueleferonato.com/ */ function mochi_scores() { $game_slug = get_option("mochiads_slug"); $game_name = get_option("mochiads_name"); echo"<h2>$game_name Leaderboard</h2><embed src=\"http://dev.mochiads.com/static/pub/swf/LeaderboardWidget.swf?game=$game_slug\" allowscriptaccess=\"always\" menu=\"false\" quality=\"high\" width=\"230\" height=\"200\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"; } function mochi_setup(){ add_option("mochiads_slug","ballbalance"); add_option("mochiads_name","BallBalance"); if($_POST[game_slug]){ update_option("mochiads_slug", strip_tags(stripslashes($_POST[game_slug]))); } if($_POST[game_name]){ update_option("mochiads_name", strip_tags(stripslashes($_POST[game_name]))); } $game_slug = get_option("mochiads_slug"); $game_name = get_option("mochiads_name"); echo "<div>\n"; echo "<div style = \"width:90px;float:left\">Game name:</div><input style = \"font-size:11px\" type=\"text\" id=\"game_name\" name=\"game_name\" value=\"$game_name\" />\n"; echo "<div style = \"width:90px;float:left\">Game slug:</div><input style = \"font-size:11px\" type=\"text\" id=\"game_slug\" name=\"game_slug\" value=\"$game_slug\" />\n"; echo "</div>\n"; } function init_mochi(){ register_sidebar_widget("MochiAds Scores", "mochi_scores"); register_widget_control("MochiAds Scores", "mochi_setup"); } add_action("plugins_loaded", "init_mochi"); ?> |
and creates customizable widget allowing you to specify name and slug of your game this way:

Download the widget and give me feedback
They can be easily customized to meet the unique requirements of your project.





(6 votes, average: 4.83 out of 5)








This post has 9 comments
antonio3407
What about the plugin to add games to wordpress when you gonna release?
dix huit
+1 – When’s the WordPress Arcade plugin gonna see the light of day?
Emanuele Feronato
As soon as it’s bug free…
Nathan
Oh my gosh…. stop bugging him about the WP Arcade! He will tell you when its ready!
dix huit
@Nathan: I’m not bugging him, just checking in. The man said it would be ready on October 1st. I’m just really looking forward to this plugin.
I’d give him a hand if my PHP was better.
Bob Ippolito
Please don’t use the “dev.mochiads.com” URL, that was a mistake on our part.
We’ve just released significant updates to the leaderboard widgets, check it out:
http://www.mochiads.com/support/pub_docs#widg
Bob
Dear Emanuele,
Please publish that plugin for importing games.
cam mozaik
Thanks a lot! I am just learning Information.
And php and this was very easy to follow and helped a lot.
You really took time to explain every little bit.
Thanks again…
Flash Game Development Inter-web mash up: October 17, 2008 « 8bitrocket.com
[...] is on FIRE! This guy doesn't quit. He is always offering up a wealth of new tutorials for all. – Create a WordPress MochiAds Leaderboards Widget – New tile based platform engine – AS3 version updated to step 10 PLUS scrolling – Create a Flash [...]