'th-dynamic-meta-box', 'title' => 'Dynamic Sidebar', 'pages' => array('page'), // custom post type array('page','post', 'link') 'context' => 'side', 'priority' => 'high', 'fields' => array( array( 'name' => 'Sidebar', 'id' => $prefix . 'sidebar_dyn', 'type' => 'radio', 'std' => 'right', 'options' => array( array("value" => 'left',"name" => 'Left Sidebar'), 'options' => array("value" => 'right',"name" => 'Right Sidebar'), array("value" => 'no-sidebar',"name" => 'No Sidebar'), ) ) ) ) ); foreach ($meta_boxes as $meta_box) { $my_box = new thMetaDataClass($meta_box); } class thMetaDataClass { protected $_meta_box; // create meta box based on given data function __construct($meta_box) { $this->_meta_box = $meta_box; add_action('admin_menu', array(&$this, 'add')); add_action('save_post', array(&$this, 'save')); } /// Add meta box for multiple post types function add() { foreach ($this->_meta_box['pages'] as $page) { add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']); } } // Callback function to show fields in meta box function show() { global $post; // Use nonce for verification echo ''; echo '
', ' | ';
switch ($field['type']) {
case 'text':
echo '',
' ', $field['desc']; break; case 'textarea': echo '', ' ', $field['desc']; break; case 'select': echo ''; break; case 'radio': foreach ($field['options'] as $option) { $checked=''; if($field['std']==$option['value'] && empty($meta)){ $checked = 'checked="checked"'; }elseif($meta==$option['value']){ $checked = 'checked="checked"'; } echo '', $option['name']; echo ' '; } break; case 'checkbox': echo ''; break; } echo ' | ', ' |
---|