JPry

Untitled

May 1st, 2012
62
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.         'show_in_nav_menus' => true,
  37.         'publicly_queryable' => true,
  38.         'exclude_from_search' => false,
  39.         'has_archive' => true,
  40.         'query_var' => true,
  41.         'can_export' => true,
  42.         'rewrite' => true,
  43.         'capability_type' => 'post'
  44.     );
  45.  
  46.     register_post_type( 'artist', $args );
  47. }
  48.  
  49. function be_sample_metaboxes( $meta_boxes ) {
  50.     $prefix = '_cmb_ds_';
  51.     $meta_boxes[] = array(
  52.         'id' => 'test_metabox',
  53.         'title' => 'Test Metabox',
  54.         'pages' => array('artist'), // post type
  55.         'context' => 'normal',
  56.         'priority' => 'high',
  57.         'show_names' => true, // Show field names on the left
  58.         'fields' => array(
  59.             array(
  60.                 'name' => 'Test Text',
  61.                 'desc' => 'Dummy text to see what happens',
  62.                 'id' => $prefix . 'test_text',
  63.                 'type' => 'text'
  64.             ),
  65.         ),
  66.     );
  67.  
  68.     return $meta_boxes;
  69. }
  70. add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );
  71.  
  72. // Initialize the metabox class
  73. add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
  74. function be_initialize_cmb_meta_boxes() {
  75.     if ( !class_exists( 'cmb_Meta_Box' ) ) {
  76.         require_once( 'lib/metabox/init.php' );
  77.     }
  78. }
  79.  
  80. This is the single-artist.php code:
  81. <?php
  82. /*
  83.  * Template Name: Artist
  84.  * This template displays Artist Details
  85.  */
  86.  
  87. remove_action('genesis_after_post_content', 'genesis_post_meta'); //remove post-meta
  88. remove_action('genesis_before_post_content', 'genesis_post_info'); //remove post-info
  89. add_action('genesis_after_post_content', 'child_get_artists_field'); //display meta-box content after the content
  90.  
  91. //Function to show the content
  92. function child_get_artists_field() {
  93.         echo '<strong>Bacon '. genesis_get_custom_field( '_cmb_ds_test_text' ) .'</strong>';
  94. }
  95.  
  96. genesis(); // requires Genesis 1.3+  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment