General setup question
-
SO when i am adding meta boxes in my function file do i need to add a function everytime i add a prefix? or do i just change the prefix to something like $prefix_two? Or am i doing it completely wrong. Here is my code for my home page meta boxes.
/* ********* adding custom metaboxes ***************** */ add_action( 'cmb2_admin_init', 'home_custom_metaboxes' ); /** * Define the metabox and field configurations. */ function home_custom_metaboxes() { // Start with an underscore to hide fields from custom fields list $prefix = '_section_one_content'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'section_one_content', 'title' => __( 'Section One Content', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'cmb_styles' => true, // false to disable the CMB stylesheet 'closed' => false, // Keep the metabox closed by default 'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox ) ); // main section headline $cmb->add_field( array( 'name' => __( 'Headline', 'cmb2' ), 'desc' => __( 'add a headline for the about section', 'cmb2' ), 'id' => $prefix . '_text', 'type' => 'text' ) ); // headline for first about section $cmb->add_field( array( 'name' => __( 'Content Headline', 'cmb2' ), 'desc' => __( 'add a headline for the first about section content', 'cmb2' ), 'id' => $prefix . '_textarea', 'type' => 'textarea' ) ); // Text for first about section $cmb->add_field( array( 'name' => __( 'Content Text', 'cmb2' ), 'desc' => __( 'add some text for the first about section', 'cmb2' ), 'id' => $prefix . '_textarea2', 'type' => 'textarea' ) ); // image for first about section $cmb->add_field( array( 'name' => __( 'Section Background Image', 'cmb2' ), 'desc' => __( 'Upload an image or enter a URL for the first about section background.', 'cmb2' ), 'id' => $prefix . '_image', 'type' => 'file', ) ); // headline for second about section $cmb->add_field( array( 'name' => __( 'Content Headline', 'cmb2' ), 'desc' => __( 'add a headline for the second about section content', 'cmb2' ), 'id' => $prefix . '_textarea3', 'type' => 'textarea' ) ); // Text for second about section $cmb->add_field( array( 'name' => __( 'Content Text', 'cmb2' ), 'desc' => __( 'add some text for the second about section', 'cmb2' ), 'id' => $prefix . '_textarea4', 'type' => 'textarea' ) ); // image for second about section $cmb->add_field( array( 'name' => __( 'Section Background Image', 'cmb2' ), 'desc' => __( 'Upload an image or enter a URL for the second about section background.', 'cmb2' ), 'id' => $prefix . '_image2', 'type' => 'file', ) ); // Start with an underscore to hide fields from custom fields list $prefix = '_section_two_content'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'section_two_content', 'title' => __( 'Section Two Content', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'cmb_styles' => true, // false to disable the CMB stylesheet 'closed' => false, // Keep the metabox closed by default 'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox ) ); // main section headline $cmb->add_field( array( 'name' => __( 'Headline', 'cmb2' ), 'desc' => __( 'add a headline for the purveyors section', 'cmb2' ), 'id' => $prefix . '_text', 'type' => 'text' ) ); // purveyor section content headline $cmb->add_field( array( 'name' => __( 'Content Headline', 'cmb2' ), 'desc' => __( 'add a headline for the purveyors content section', 'cmb2' ), 'id' => $prefix . '_text2', 'type' => 'text' ) ); // Content text for purveyors section $cmb->add_field( array( 'name' => __( 'Content Text', 'cmb2' ), 'desc' => __( 'add some text for the purveyors section', 'cmb2' ), 'id' => $prefix . '_textarea', 'type' => 'textarea' ) ); // Start with an underscore to hide fields from custom fields list $prefix = '_section_three_content'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'section_three_content', 'title' => __( 'Section Three Content', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'cmb_styles' => true, // false to disable the CMB stylesheet 'closed' => false, // Keep the metabox closed by default 'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox ) ); // main section headline $cmb->add_field( array( 'name' => __( 'Headline', 'cmb2' ), 'desc' => __( 'add a headline for the Look Around Section', 'cmb2' ), 'id' => $prefix . '_text', 'type' => 'text' ) ); $cmb->add_field( array( 'name' => __( 'Multiple Slide Images', 'cmb2' ), 'desc' => __( 'Upload Images for Slides', 'cmb2' ), 'id' => $prefix . '_file_list', 'type' => 'file_list', 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 ) ) ); // Start with an underscore to hide fields from custom fields list $prefix = '_section_four_content'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'section_four_content', 'title' => __( 'Section Four Content', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'cmb_styles' => true, // false to disable the CMB stylesheet 'closed' => false, // Keep the metabox closed by default 'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox ) ); // main section headline $cmb->add_field( array( 'name' => __( 'Headline', 'cmb2' ), 'desc' => __( 'add a headline for the Lets Talk About It Section', 'cmb2' ), 'id' => $prefix . '_text', 'type' => 'text' ) ); // Add other metaboxes as needed }i basically want a new meta box for each section so they can be opened and closed so i guess i just need to know if the code is set up right or if i am doing something wrong. Everything is working, I don’t want ot have any conflicts later on down the road. thanks for any help
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘General setup question’ is closed to new replies.