Create a Custom Post Type named “Gig” and WordPress will take care of the UI creation, then all that is left for you is to add a Metabox with the fields you want (date, venue, about).
Here is a simple step by step guide:
First: Register Your Gig Post Type
//register your custom post type gig
add_action( 'init', 'register_cpt_gig' );
function register_cpt_gig() {
$labels = array(
'name' => _x( 'gigs', 'gig' ),
'singular_name' => _x( 'gig', 'gig' ),
'add_new' => _x( 'Add New', 'gig' ),
'add_new_item' => _x( 'Add New gig', 'gig' ),
'edit_item' => _x( 'Edit gig', 'gig' ),
'new_item' => _x( 'New gig', 'gig' ),
'view_item' => _x( 'View gig', 'gig' ),
'search_items' => _x( 'Search gigs', 'gig' ),
'not_found' => _x( 'No gigs found', 'gig' ),
'not_found_in_trash' => _x( 'No gigs found in Trash', 'gig' ),
'parent_item_colon' => _x( 'Parent gig:', 'gig' ),
'menu_name' => _x( 'Gigs', 'gig' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'just a simple "where, when, with who" kind of thing',
'supports' => array( 'title', 'custom-fields' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'http://i.imgur.com/4nTMD.png',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type'=> 'post'
);
register_post_type( 'gig', $args );
}
This will give you a new Post Type and an admin UI for creating your gigs:
Next you need to create a Metabox (to avoid using the regular custom fields)
There are a million tutorials online on how to create and add your Metabox so I’m not going into that but I’ll show you a fast easy way to do it.
Download this class and once you put this in your theme the creation of the Metabox should be something like this:
if( is_admin() ) {
//include the main class file
require_once( "meta-box-class/my-meta-box-class.php" );
$prefix = '_gigs';
//configure your meta box
$config = array(
'id' => 'gigs-info',
'title' => 'Gig Info',
'pages' => array('gig'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(),
'local_images' => false,
'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).
);
$my_meta = new AT_Meta_Box( $config );
//Add fields to your meta box
$my_meta->addText( $prefix . 'where', array( 'name'=> 'Where is the Gig ' ) );
$my_meta->addDate( $prefix . 'when', array( 'name'=> 'When is the Gig ' ) );
$my_meta->addTime( $prefix . 'start_time', array( 'name'=> 'When Does it Start ' ) );
$my_meta->addTime( $prefix . 'end_time', array( 'name'=> 'When Does it End ' ) );
$my_meta->addText( $prefix . 'with_who', array( 'name'=> 'With Who is the Gig ' ) );
$my_meta->addTextarea( $prefix . 'words', array( 'name'=> 'A few words on the gig ' ) );
$my_meta->Finish();
}
You will end up with something looking similar to this:
Here’s another image to show the fancy timepicker:
To read more on the field types you can use and add to your Metabox read this.
That’s about it! Just to wrap up I’m posting this as a plugin to test but make sure you download the Metabox class first so it will work.
<?php
/*
Plugin Name: wp-gigs
Plugin URI: http://en.bainternet.info
Description: create list of gigs.
Version: 0.1
Author: Bainternet
Author URI: http://en.bainternet.info
*/
//register your custom post type gig
add_action( 'init', 'register_cpt_gig' );
function register_cpt_gig() {
$labels = array(
'name' => _x( 'gigs', 'gig' ),
'singular_name' => _x( 'gig', 'gig' ),
'add_new' => _x( 'Add New', 'gig' ),
'add_new_item' => _x( 'Add New gig', 'gig' ),
'edit_item' => _x( 'Edit gig', 'gig' ),
'new_item' => _x( 'New gig', 'gig' ),
'view_item' => _x( 'View gig', 'gig' ),
'search_items' => _x( 'Search gigs', 'gig' ),
'not_found' => _x( 'No gigs found', 'gig' ),
'not_found_in_trash' => _x( 'No gigs found in Trash', 'gig' ),
'parent_item_colon' => _x( 'Parent gig:', 'gig' ),
'menu_name' => _x( 'Gigs', 'gig' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'just a simple "where, when, with who" kind of thing',
'supports' => array( 'title', 'custom-fields' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'http://i.imgur.com/4nTMD.png',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'gig', $args );
}
if( is_admin() ) {
//include the main class file
require_once( "meta-box-class/my-meta-box-class.php" );
$prefix = '_gigs';
//configure your meta box
$config = array(
'id' => 'gigs-info',
'title' => 'Gig Info',
'pages' => array( 'gig' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(),
'local_images' => false,
'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).
);
$my_meta = new AT_Meta_Box( $config );
//Add fields to your meta box
$my_meta->addText( $prefix . 'where', array( 'name'=> 'Where is the Gig ' ) );
$my_meta->addDate( $prefix . 'when', array( 'name'=> 'When is the Gig ' ) );
$my_meta->addTime( $prefix . 'start_time', array( 'name'=> 'When Does it Start ' ) );
$my_meta->addTime( $prefix . 'end_time', array( 'name'=> 'When Does it End ' ) );
$my_meta->addText( $prefix . 'with_who', array( 'name'=> 'With Who is the Gig ' ) );
$my_meta->addTextarea( $prefix . 'words', array( 'name'=> 'A few words on the gig ' ) );
$my_meta->Finish();
}