Overview

Welcome to the Betta Boxes CMS plugin. This plugin turns your WordPress Blog into a powerful CMS, without the need to get down and dirty in the source code. Betta Boxes gives you a clean, simple administration interface to create custom fields, and link them to Posts, Pages, and any Custom Post Types you have!

Betta Boxes uses the default WordPress functionality of 'post meta'. This means the plugin works with WordPress, rather than fighting against it.

Installation

  1. Unzip the plugin to your wp-content/plugins/ directory.
  2. Activate the plugin through the WordPress 'Plugins' menu in the administration area.
  3. This will create a new menu item under 'settings' in the WordPress administration area, labeled Betta Boxes.

Creating Meta Boxes and Custom Fields

Once you have activated the plugin via the WordPress plugin manager, you will see a new item under the 'settings' section of the administration area labeled Betta Boxes
All the options for creating and managing Meta Boxes and Custom Fields are under here.

Click the 'Add New' link to create a meta box.
You need to add a Title, and choose which post type to show the box in. Posts, pages and any custom post types declared will be available for selection.

Click 'Add Field' to add a new custom field inside the meta box. You can choose from a number of types (see below). Each custom field requires you give it a label and a unique meta key. The label is used as the fields label when you add/edit a post type item. The meta key is important, and is used to identify the field in the database, and in calls to get_post_meta() to show the data in your front end templates.
You may add as many custom fields to the meta box as you want. You can drag them around to re-order them.

Once you save the meta box, it will appear on the selected post type, when you add or edit an item of that type.

Show Custom Fields in Templates

All the custom fields are saved with the WordPress function add_post_meta(). This makes getting the data in your templates very simple. Simply call get_post_meta() using the meta key you specified when creating the custom field.

For example, if you created a short text field with the meta key my-text, you would call it like this in your template:

<?php echo get_post_meta(get_the_ID(), 'my-text', true); ?>
See more specific examples below.

Types

Here is a list of all the custom field types, how they are saved in the database, and an example of 2 of using them in your templates.
For the examples, the code assumes you have used the meta key the-meta-key for the field. Just replace this with your actual meta key.

Short Text
Saved in the database as the inputed text.

Some short data: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>

Long Text
Saved in the database as the inputed text.

Postal Address: <?php echo nl2br(get_post_meta(get_the_ID(), 'the-meta-key', true)); /*nl2br makes the [enter] key into a line break in HMTL*/ ?>

Checkboxes
Saved in the database as an array of the selected elements.

<?php
//show all checked
$checked = get_post_meta(get_the_ID(), 'the-meta-key', true);
foreach ((array)$checked as $key=>$val) {
	echo $val.'<br />';
}

//check specific options are checked
$checked = get_post_meta(get_the_ID(), 'the-meta-key', true);
if($checked['Some option']) {
	echo '<strong>Some option</strong> was checked<br />';
}else{
	echo '<strong>Some option</strong> was not checked<br />';
}

if($checked['Another option']) {
	echo '<strong>Another option</strong> was checked<br />';
}else{
	echo '<strong>Another option</strong> was not checked<br />';
}
?>

Radio buttons
Saved in the database as the selected option.

Selected: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>

Drop Down
Saved in the database as the selected option.

Selected: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>

HTML WYSIWYG
Saved in the database as the HTML source.

HTML: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>

Color
Saved in the database WITHOUT the hash.

<div style="background-color:#<?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>">Some now colored div</div>

Date
Saved in the database in the format YYYY-MM-DD.

Date like YYYY-MM-DD: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>
Date like 17 August 2011: <?php echo date('j F Y', strtotime(get_post_meta(get_the_ID(), 'the-meta-key', true))); /*Using PHP date format, more here: http://www.php.net/manual/en/function.date.php */ ?>

Time
Saved in the database in the format HH:MM:SS

Start Time: <?php echo get_post_meta(get_the_ID(), 'the-meta-key', true); ?>