In this chapter, we will show you how to create custom WP Arcade Themes that will be compatible with MyArcadePlugin. We have built a set of functions (MyArcadePlugin Theme API) to make your life easier. These functions will provide you an easy way to retrieve and display game details in your theme.

All of these functions have to be used within the WordPress Loop!

MyArcadePlugin Custom Fields

MyArcadePlugin uses WordPress custom fields to saves game details. Game description and instructions are saved as WordPress post content. The post content generation can be adjusted at the MyArcadePlugin’s Settings Panel (General Settings).

List of MyArcadePlugin custom fields:

  • mabp_swf_url – Stores the URL, Embed Code or Iframe code of the game.
  • mabp_height – Stores game height in pixels
  • mabp_width – Stores game width in pixels
  • mabp_thumbnail_url – Stores game thumbnail URL
  • mabp_screen1_url – Stores game screenshot 1 URL
  • mabp_screen2_url – Stores game screenshot 2 URL
  • mabp_screen3_url – Stores game screenshot 3 URL
  • mabp_screen4_url – Stores game screenshot 4 URL
  • mabp_leaderboard – Is set to 1 when the game is able to submit scores

You can retrieve all of these custom fields with the standard WordPress function “get_post_meta” but we would recommend you to use our MyArcadePlugin Theme API.

List of all available functions:

  1. myarcade_get_leaderboard_code
  2. get_game
  3. is_game
  4. myarcade_title
  5. myarcade_excerpt
  6. myarcade_thumbnail
  7. myarcade_get_thumbnail_url
  8. myarcade_count_screenshots
  9. myarcade_screenshot
  10. myarcade_get_screenshot_url
  11. myarcade_all_screenshots

MyArcadePlugin Function Reference

The following functions are included in MyArcadePlugin and you can use them as soon as MyArcadePlugin is installed.

Function: myarcade_get_leaderboard_code

Description

Returns the Mochimedia’s Leaderboard Bridge integration and must be called if you want to enable to collect user scores.

This function is a part of MyArcadePlugin.

Usage

<?php echo myarcade_get_leaderboard_code(); ?>

Parameters

none

Example

<?php
if (function_exists('myarcade_get_leaderboard_code')) {
  echo myarcade_get_leaderboard_code();
}
?>

In Addition to the function call the Mochi Leaderboard JavaScript Library must be added to the theme header or footer. It should be sufficient when the Leaderboard JS lib is included only on the game play page:
<?php
add_action('wp_print_scripts', 'mytheme_scripts_init');

function mytheme_scripts_init() { if ( is_single() ) { wp_enqueue_script( 'leaderboard', 'http://xs.mochiads.com/static/pub/swf/leaderboard.js', '', '', false ); } } ?>

Function: get_game

Description

Returns the game embed code depended on the game type.

This function is a part of MyArcadePlugin.

Usage

<?php get_game($postID, $fullsize, $preview, $fullscreen); ?>

Parameters

$gameID

  • (int) Post ID
  • Default: None

$fullsize

  • (bool) (optional) Set always to FALSE
  • deprecated or for internal use only

$preview

  • (bool) (optional) Set always to FALSE
  • deprecated or for internal use only

$fullscreen

  • (bool) (optional) TRUE or FALSE
  • If set to TRUE the function will set game width and height to 93%
  • Useful if your theme has a fullscreen feature

 

Example

This is the example code we use in our default theme.

<?php
if (function_exists('get_game')) {
  /* mypostid global is needed for MyScoresPresenter */
  global $mypostid; $mypostid = $post->ID;
  echo myarcade_get_leaderboard_code();
  echo get_game($post->ID);
}
?>

This example will show you how to display the game in fullscreen
<?php
if (function_exists('get_game')) {
  /* mypostid global is needed for MyScoresPresenter */
  global $mypostid; $mypostid = $post->ID;
  echo myarcade_get_leaderboard_code();
  echo get_game($post->ID, false, false, true);
}
?>

Function: is_game

Description

The Conditional Tag checks if the currently displayed post is a game. This is a boolean function, meaning it returns either TRUE or FALSE.

This function is a part of MyArcadePlugin.

Usage

<?php is_game(); ?>

Parameters

none

Return Values

(boolean) TRUE on success, FALSE on failure.

Example

To check if the displayed post is a game you can use this code snippet:

<?php
if ( is_game() ) {
  // do something ..
}
?>

MyArcadePlugin Theme API Function Reference

Do be able to use our MyArcadePlugin Theme API you will need to include the API in your theme functions.php:

/** Include MyArcadePlugin Theme API **/
include_once('myarcade_api.php');

myarcade_api.php should be placed in your theme folder where the functions.php is located.

Download: MyArcadePlugin Theme API

Function: myarcade_title

Description

Displays or returns the title of the current game / post. The title can be cut after the given number of characters. The function will not cut words. It will search for a whitespace and then cut the title.

Usage

<?php myarcade_title($chars, $echo); ?>

Parameters

$chars

  • (int) Maximal characters of the title
  • Default 0: The complete title will be displayed or returned.

$echo

  • (boolean) Whether to display or return the title
  • Default TRUE: The title will be displayed (echo)

Example

Display maximal 20 characters of the game title.

<?php myarcade_title(20); ?>

Function: myarcade_excerpt

Description

Displays or returns the excerpt of a game post. All tags will be removed. An excerpt of maximal 100 words will be generated and then it can be cut with the given $length.

Usage

<?php myarcade_excerpt($length, $echo); ?>

Parameters

$length

  • (int) Maximal characters of the excerpt
  • Default FALSE: Display the entire excerpt (100 words).

$echo

  • (boolean) Whether to display or return the excerpt
  • Default TRUE: The excerpt will be displayed (echo)

Example

Display an excerpt with maximal 150 characters.

<?php myarcade_excerpt(150); ?>

Function: myarcade_thumbnail

Description

Display or returns the thumbnail image tag of the current game. If no thumbnail is available the function will display the default image located in the theme image directory:

wp-content/themes/yourtheme/images/def_thumb.png

Usage

<?php myarcade_thumbnail($width, $height, $class); ?>

Parameters

$width

  • (int) (optional) Width of the thumbnail
  • Default 100

$height

  • (int) (optional) Height of the thumbnail
  • Default 100

$class

  • (string) (optional) CSS class for the generated img tag
  • Default none

Example

Display the game thumbnail as 75x75px:

<?php myarcade_thumbnail(75, 75); ?>

The HTML output will looks like this:
<img src="URL_TO_THUMBAIL" width="75" height="75" alt="GAME_TITLE" />

To add an specific css class to the output add the $class parameter:
<?php myarcade_thumbnail(75, 75, 'glossy'); ?>

The HTML output will looks like this:
<img src="URL_TO_THUMBAIL" width="75" height="75" alt="GAME_TITLE" class="glossy" />

Function:  myarcade_get_thumbnail_ur

Description

Returns the thumbnail URL of a game.

Usage

<?php myarcade_get_thumbnail_url(); ?>

Parameters

none

Return Values

(string) URL to a thumbnail

Example

Get the URL of a thumbnail and store it in a var:

<?php $thumb = myarcade_get_thumbnail_url(); ?>

Function: myarcade_count_screenshots

Description

Returns the number of available screenshots of a game.

Usage

<?php myarcade_count_screenshots(); ?>

Parameters

none

Return Values

(int) Number of available screenshots

Example

<?php $screenshots = myarcade_count_screenshots(); ?>

Function: myarcade_screenshot

Description

Display the given game screenshot

Usage

<?php myarcade_screenshot($width, $height, $number, $class); ?>

Parameters

$width

  • (int) (optional) Width of the screenshot
  • Default 450

$height

  • (int) (optional) Height of the screenshot
  • Default 300

$number

  • (int) (optional) Number of the screenshot (1, 2,3 or 4)
  • Default 1

$class

  • (string) (optional) CSS class for the generated img tag
  • Default none

Example

Display the first screenshot with dimensions 300x250px and css class ‘glossy':

<?php myarcade_screenshot(300, 250, 1, 'glossy'); ?>

The HTML output will looks like this:
<img src="URL_TO_SCREENSHOT" width="300" height="250" alt="GAME_TITLE" class="glossy" />

Function: myarcade_get_screenshot_url

Description

Displays or returns the URL of a screenshot.

Usage

<?php myarcade_get_screenshot_url($number, $echo); ?>

Parameters

$number

  • (int) (optional) Number of the screenshot (1, 2,3 or 4)
  • Default 1

$echo

  • (boolean) Whether to display or return the URL
  • Default TRUE: The URL will be displayed (echo)

Example

Echo the URL of the first screenshot:

<?php myarcade_get_screenshot_url(); ?>

Function: myarcade_all_screenshots

Description

Display all screenshots and link to the images. This function adds rel=’lightbox’ to links automatically (Lightbox Plus Plugin Support).

Usage

<?php myarcade_all_screenshots($width, $height, $class); ?>

Parameters

$width

  • (int) (optional) Width of the screenshot
  • Default 450

$height

  • (int) (optional) Height of the screenshot
  • Default 300

$class

  • (string) (optional) CSS class for the generated img tag
  • Default none

Example

Display all screenshots with 130x130px thumbnails and add the screen_thumb class;

<?php myabp_print_screenshot_all(130, 130, 'screen_thumb'); ?>

For each available screenshot the function will generate such output:
<a href="SCREENSHOT_URL" title="GAME_TITLE" rel="lightbox"><img src="SCREENSHOT_URL" width="130" height="130" alt="GAME_TITLE" class="screen_thumb" /></a>