Advertisement
JPry

CMB for Dorian

May 1st, 2012
33
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. /**
  52.  * Either declare the $prefix variable globally here, or else
  53.  * declare it within the function itself (NOT globally).
  54.  *
  55.  * The main reason for a global $prefix variable is if you're creating
  56.  * lots of metaboxes using different functions, and you want to set the
  57.  * $prefix in just one place.
  58.  */
  59. global $prefix;
  60. $prefix = '_cmb_'; // Prefix for all fields
  61. function be_sample_metaboxes( $meta_boxes ) {
  62.     global $prefix;
  63.     $meta_boxes[] = array(
  64.         'id' => 'test_metabox',
  65.         'title' => 'Test Metabox',
  66.         'pages' => array('artist'), // post type
  67.         'context' => 'normal',
  68.         'priority' => 'high',
  69.         'show_names' => true, // Show field names on the left
  70.         'fields' => array(
  71.             array(
  72.                 'name' => 'Test Text',
  73.                 'desc' => 'Dummy text to see what happens',
  74.                 'id' => $prefix . 'test_text',
  75.                 'type' => 'text'
  76.             ),
  77.         ),
  78.     );
  79.  
  80.     return $meta_boxes;
  81. }
  82. add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );
  83.  
  84. // Initialize the metabox class
  85. add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
  86. function be_initialize_cmb_meta_boxes() {
  87.     if ( !class_exists( 'cmb_Meta_Box' ) ) {
  88.         require_once( 'lib/metabox/init.php' );
  89.     }
  90. }
  91.  
  92. This is the single-artist.php code:
  93. <?php
  94. /*
  95.  * Template Name: Artist
  96.  * This template displays Artist Details
  97.  */
  98.  
  99. remove_action('genesis_after_post_content', 'genesis_post_meta'); //remove post-meta
  100. remove_action('genesis_before_post_content', 'genesis_post_info'); //remove post-info
  101. add_action('genesis_after_post_content', 'child_get_artists_field'); //display meta-box content after the content
  102.  
  103. //Function to show the content
  104. function child_get_artists_field() {
  105.         echo '<strong>Bacon'. genesis_get_custom_field('_cmb_test_metabox)') .'</strong>';
  106. }
  107.  
  108. genesis(); // requires Genesis 1.3+  
  109. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement