-
Notifications
You must be signed in to change notification settings - Fork 88
Useage
hannit edited this page Oct 22, 2012
·
2 revisions
#Simple Usage Demo
if (is_admin()){
//include the main class file
require_once("meta-box-class/my-meta-box-class.php");
/*
* prefix of meta keys, optional
* use underscore (_) at the beginning to make keys hidden, for example $prefix = '_ba_';
* you also can make prefix empty to disable it
*
*/
$prefix = 'ba_';
/*
* configure your meta box
*/
$config = array(
'id' => 'demo_meta_box', // meta box id, unique per meta box
'title' => 'Demo Meta Box', // meta box title
'pages' => array('post', 'page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(), // list of meta fields (can be added by field arrays)
'local_images' => false, // Use local or hosted images (meta box images for add/remove)
'use_with_theme' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
/*
* Initiate your meta box
*/
$my_meta = new AT_Meta_Box($config);
/*
* Add fields to your meta box
*/
//text field
$my_meta->addText($prefix.'text_field_id',array('name'=> 'My Text Field'));
//textarea field
$my_meta->addTextarea($prefix.'textarea_field_id',array('name'=> 'My Textarea Field'));
//checkbox field
$my_meta->addCheckbox($prefix.'checkbox_field_id',array('name'=> 'My Checkbox Field'));
//select field
$my_meta->addSelect($prefix.'select_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> 'My select Field', 'std'=> array('selectkey2')));
//checkboxList
$my_meta->addCheckboxList($prefix.'ch_list_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> 'My CheckBox List Field', 'std'=> array('selectkey2')));
//radio field
$my_meta->addRadio($prefix.'radio_field_id',array('radiokey1'=>'Radio Value1','radiokey2'=>'Radio Value2'),array('name'=> 'My Radio Filed', 'std'=> array('radionkey2')));
//date field
$my_meta->addDate($prefix.'date_field_id',array('name'=> 'My Date Field'));
//Time field
$my_meta->addTime($prefix.'time_field_id',array('name'=> 'My Time Field'));
//Color field
$my_meta->addColor($prefix.'color_field_id',array('name'=> 'My Color Field'));
//Image field
$my_meta->addImage($prefix.'image_field_id',array('name'=> 'My Image Field'));
//file upload field
$my_meta->addFile($prefix.'file_field_id',array('name'=> 'My File Field'));
//wysiwyg field
$my_meta->addWysiwyg($prefix.'wysiwyg_field_id',array('name'=> 'My wysiwyg Editor Field'));
//taxonomy field
$my_meta->addTaxonomy($prefix.'taxonomy_field_id',array('taxonomy' => 'category'),array('name'=> 'My Taxonomy Field'));
//posts field
$my_meta->addPosts($prefix.'posts_field_id',array('post_type' => 'post'),array('name'=> 'My Posts Field'));
/*
* To Create a reapeater Block first create an array of fields
* use the same functions as above but add true as a last param
*/
$repeater_fields[] = $my_meta->addText($prefix.'text_field_id',array('name'=> 'My Text Field'),true);
$repeater_fields[] = $my_meta->addTextarea($prefix.'textarea_field_id',array('name'=> 'My Textarea Field'),true);
$repeater_fields[] = $my_meta->addCheckbox($prefix.'checkbox_field_id',array('name'=> 'My Checkbox Field'),true);
/*
* Then just add the fields to the repeater block
*/
//repeater block
$my_meta->addRepeaterBlock($prefix.'text_field_id',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields));
/*
* Don't Forget to Close up the meta box decleration
*/
//Finish Meta Box Decleration
$my_meta->Finish();
}