Advertisement
JPry

CMB for Dorian

May 1st, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This is the functions.php from the plugin that creates the CPT and the metaboxes
  2. <?php
  3.  
  4. /*
  5. Plugin Name: Scrutinies Functions
  6. */
  7.  
  8. add_action( 'init', 'register_cpt_artist' );
  9.  
  10. function register_cpt_artist() {
  11.  
  12.     $labels = array(
  13.         'name' => _x( 'Artists', 'artist' ),
  14.         'singular_name' => _x( 'Artist', 'artist' ),
  15.         'add_new' => _x( 'Add New', 'artist' ),
  16.         'add_new_item' => _x( 'Add New Artist', 'artist' ),
  17.         'edit_item' => _x( 'Edit Artist', 'artist' ),
  18.         'new_item' => _x( 'New Artist', 'artist' ),
  19.         'view_item' => _x( 'View Artist', 'artist' ),
  20.         'search_items' => _x( 'Search Artists', 'artist' ),
  21.         'not_found' => _x( 'No artists found', 'artist' ),
  22.         'not_found_in_trash' => _x( 'No artists found in Trash', 'artist' ),
  23.         'parent_item_colon' => _x( 'Parent Artist:', 'artist' ),
  24.         'menu_name' => _x( 'Artists', 'artist' ),
  25.     );
  26.  
  27.     $args = array(
  28.         'labels' => $labels,
  29.         'hierarchical' => false,
  30.         'description' => 'Interviews with Catholic artists.',
  31.         'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'custom-fields', 'comments' ),
  32.         'taxonomies' => array( 'category', 'specialty' ),
  33.         'public' => true,
  34.         'show_ui' => true,
  35.         'show_in_menu' => true,
  36.        
  37.        
  38.         'show_in_nav_menus' => true,
  39.         'publicly_queryable' => true,
  40.         'exclude_from_search' => false,
  41.         'has_archive' => true,
  42.         'query_var' => true,
  43.         'can_export' => true,
  44.         'rewrite' => true,
  45.         'capability_type' => 'post'
  46.     );
  47.  
  48.     register_post_type( 'artist', $args );
  49. }
  50.  
  51. $prefix = '_cmb_'; // Prefix for all fields
  52. function be_sample_metaboxes( $meta_boxes ) {
  53.     global $prefix;
  54.     $meta_boxes[] = array(
  55.         'id' => 'test_metabox',
  56.         'title' => 'Test Metabox',
  57.         'pages' => array('artist'), // post type
  58.         'context' => 'normal',
  59.         'priority' => 'high',
  60.         'show_names' => true, // Show field names on the left
  61.         'fields' => array(
  62.             array(
  63.                 'name' => 'Test Text',
  64.                 'desc' => 'Dummy text to see what happens',
  65.                 'id' => $prefix . 'test_text',
  66.                 'type' => 'text'
  67.             ),
  68.         ),
  69.     );
  70.  
  71.     return $meta_boxes;
  72. }
  73. add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );
  74.  
  75. // Initialize the metabox class
  76. add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
  77. function be_initialize_cmb_meta_boxes() {
  78.     if ( !class_exists( 'cmb_Meta_Box' ) ) {
  79.         require_once( 'lib/metabox/init.php' );
  80.     }
  81. }
  82.  
  83. This is the single-artist.php code:
  84. <?php
  85. /*
  86.  * Template Name: Artist
  87.  * This template displays Artist Details
  88.  */
  89.  
  90. remove_action('genesis_after_post_content', 'genesis_post_meta'); //remove post-meta
  91. remove_action('genesis_before_post_content', 'genesis_post_info'); //remove post-info
  92. add_action('genesis_after_post_content', 'child_get_artists_field'); //display meta-box content after the content
  93.  
  94. //Function to show the content
  95. function child_get_artists_field() {
  96.         echo '<strong>Bacon'. genesis_get_custom_field('_cmb_test_metabox)') .'</strong>';
  97. }
  98.  
  99. genesis(); // requires Genesis 1.3+  
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement