Last active
December 15, 2015 14:09
-
-
Save bhwebworks/5272349 to your computer and use it in GitHub Desktop.
Create the 'Slides' custom post type and custom meta boxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create the 'Slides' custom post type | |
* @since 1.0 | |
* | |
*/ | |
add_action( 'init', 'bhww_register_slides_cpt' ); | |
function bhww_register_slides_cpt() { | |
// Set up the arguments for the Slides custom post type | |
$slide_args = array( | |
'labels' => array( | |
'name' => 'Slides', | |
'singular_name' => 'Slide', | |
'add_new' => 'Add New Slide', | |
'add_new_item' => 'Add New Slide', | |
'edit_item' => 'Edit Slide', | |
'new_item' => 'New Slide', | |
'view_item' => 'View Slide', | |
'search_items' => 'Search Slides', | |
'not_found' => 'No Slides found', | |
'not_found_in_trash' => 'No Slides found in Trash' | |
), | |
'public' => true, // Make it publicly accessible | |
'hierarchical' => true, | |
'menu_position' => 5, // Appear just below 'Posts' | |
'supports' => array( 'title','editor','thumbnail' ), | |
'capability_type' => 'page', | |
'rewrite' => array( | |
'slug' => 'slide' // Use 'slide' instead of 'bhww_slide' in permalinks. Refresh permalinks after changing this slug. | |
) | |
); | |
// Register the Slides custom post type | |
register_post_type( 'bhww_slide', $slide_args ); | |
} // End bhww_register_slides_cpt | |
/** | |
* Create Custom Meta Boxes for each CPT | |
* @since 1.0 | |
* | |
* Using the Custom Metaboxes library from | |
* Andrew Norcross, Jared Atchinson, and Bill Erickson | |
* | |
* @link https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress | |
* | |
*/ | |
add_filter( 'cmb_meta_boxes', 'bhww_cpt_metaboxes' ); | |
function bhww_cpt_metaboxes( $meta_boxes ) { | |
//global $prefix; | |
$prefix = '_bhww_'; // Prefix for all fields | |
// Add Instructions and Link metaboxes to the 'Slides' CPT | |
$meta_boxes[] = array( | |
'id' => 'bhww_slides_metabox', | |
'title' => 'Slide Information', | |
'pages' => array( 'bhww_slide' ), // Which post type to associate with? | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, // Show field names on the left | |
'fields' => array( | |
array( | |
'name' => 'How to add a new slide to the slideshow', | |
'desc' => '1. Add a title at the top of this page where it says, "Enter title here." This title will appear in the text overlay of the slide.<br /> | |
2. Enter some content (text) in the text editor. This will appear under the title in the text overlay of the slide.<br /> | |
3. Upload or select an image for this slide using the "Featured Image" link. <strong>Recommended image size is 1140 x 445 pixels.</strong><br /> | |
4. Enter a link in the text box below if you\'d like the slide to link to another post, page, website, etc.', | |
'id' => $prefix . 'slide_instructions', | |
'type' => 'title', | |
), | |
array( | |
'name' => 'Slide Link', | |
'desc' => 'Enter the URL of a post, page, other website, etc. that this slide should link to.<br />For example: http://mywebsite.com/about-us', | |
'id' => $prefix . 'slide_link', | |
'type' => 'text', | |
) | |
), | |
); // End 'Slides' CPT metaboxes | |
return $meta_boxes; | |
} // End bhww_cpt_metaboxes | |
// Initialize the metabox class | |
add_action( 'init', 'bhww_cpt_initialize_cmb_meta_boxes', 9999 ); | |
function bhww_cpt_initialize_cmb_meta_boxes() { | |
if ( !class_exists( 'cmb_Meta_Box' ) ) { | |
require_once( BHWW_CORE_DIR . '/lib/metabox/init.php' ); | |
} | |
}// End bhww_cpt_initialize_cmb_meta_boxes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed hierarchical to "true" to enable Slide ordering with the Simple Page Ordering plugin