-
Notifications
You must be signed in to change notification settings - Fork 7
Custom Meta Boxes
OmniBuilder provides OmniBuilder\Custom_Meta_Box class that makes custom meta box implementation feel far more natural. Adding meta boxes to the custom post type(s) is as easy as setting up a array of Custom_Meta_Box instances that is being passed as a second argument during the new OmniBuilder\Custom_Post_Type instantiation.
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'informations', 'Informations' ),
new Custom_Meta_Box( 'related', 'Related' )
) );
Once you add one (or more) custom meta boxes you will want to add some fields to it. Currently, OmniBuilder has 7 fields in it's library and those are:
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Text;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'informations', 'Informations', array(
new Text( 'location', array(
'label' => 'Location:'
) ),
new Text( 'year', array(
'label' => 'Year:'
) )
) )
) );
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Textarea;
$book = new Custom_Post_Type( 'book', array(
new Custom_Meta_Box( 'informations', 'Informations', array(
new Textarea( 'about_author', array(
'label' => 'About the author:'
) ),
new Textarea( 'about_book', array(
'label' => 'About the book:'
) )
) )
) );
Fieldset is a field that acts as a container around one or more child fields. Fieldsets are mostly used for styling purposes and seperation of fields with the same name in order to avoid collision.
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Fieldset;
use OmniBuilder\Field\Textarea;
$book = new Custom_Post_Type( 'book', array(
new Custom_Meta_Box( 'informations', 'Informations', array(
new Fieldset( 'author', array(), array(
new Textarea( 'about', array(
'label' => 'About the author:'
) )
) ),
new Fieldset( 'book', array(), array(
new Textarea( 'about', array(
'label' => 'About the book:'
) )
) )
) )
) );
Collection field is used to render collection (array) of child fields, fieldsets or even child collections. Collection enables you to dynamicly add, delete, update and sort collection entries (rows).
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Collection;
use OmniBuilder\Field\Text;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'informations', 'Informations', array(
new Collection( 'specifications', array(), array(
new Text( 'specification', array(
'label' => 'Specification:'
) ),
new Text( 'value', array(
'label' => 'Value:'
) )
) )
) )
) );
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Checkbox;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'options', 'Options', array(
new Checkbox( 'featured', array(
'label' => 'Mark as featured'
) )
) )
) );
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Radio;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'options', 'Options', array(
new Radio( 'featured', array(
'label' => 'Mark as featured:',
'choices' => array(
'yes' => 'Yes',
'no' => 'No'
)
) )
) )
) );
use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Select;
$project = new Custom_Post_Type( 'project', array(
new Custom_Meta_Box( 'options', 'Options', array(
new Select( 'location', array(
'label' => 'Location:',
'choices' => array(
'header' => 'Header',
'sidebar' => 'Sidebar',
'footer' => 'Footer',
)
) )
) )
) );