Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to move a metabox above the main content?
This topic is: resolved
Tagged: cmb2, Custom fields, hooks, metaboxes
- This topic has 1 reply, 1 voice, and was last updated 9 years, 4 months ago by studionoobly.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
July 16, 2015 at 4:40 am #159538studionooblyMember
On a template page I have a metabox that I can get to show up below the main content of the page but now I would like to move the metabox to display just after the "content-sidebar-wrap"?
<?php /* Template Name: Custom Page Template */ /* This is the Custom page template */ // force page layout to be content then sidebar add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); // remove comments remove_action( 'genesis_comments', 'genesis_do_comments' ); // adding a custom sidebar for this page remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); add_action( 'genesis_sidebar', 'nb_do_sidebar' ); // inserting custom page content into genesis template add_action( 'genesis_after_entry', 'nb_custom_page' ); // creating custom page content function nb_custom_page() { ?> <?php $textarea = get_post_meta( get_the_ID(), '_cmb_c_textarea', true ); ?> <p><?php echo esc_html( $textarea ); ?></p> <?php } // do genesis genesis(); ?>
I have tried adding the following but the metabox disappears on the front end with no error message?
<?php $textarea = get_post_meta( get_the_ID(), '_cmb_c_textarea', true ); ?> <?php add_action( 'genesis_before_content', 'nb_do_metabox' ); function nb_do_metabox() { echo esc_html( $textarea ); } ?>
Thanks.
July 16, 2015 at 7:32 am #159557studionooblyMemberAfter much banging of head against desk, I found this solution worked for me, I'm not sure if it's the best way of doing it, if anyone has a better idea I'm all ears.
<?php /* Template Name: Custom Page Template */ /* This is the Custom page template */ // force page layout to be content then sidebar add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); // remove comments remove_action( 'genesis_comments', 'genesis_do_comments' ); // adding a custom sidebar for this page remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); add_action( 'genesis_sidebar', 'nb_do_sidebar' ); // adding two custom fields before the page content add_action( 'genesis_before_content_sidebar_wrap', 'nb_meta_box_callback' ); if (!function_exists('nb_meta_box_callback')) { function nb_meta_box_callback() { // Grab the metadata from the database $text = get_post_meta( get_the_ID(), '_cmb_text', true ); $textarea = get_post_meta( get_the_ID(), '_cmb_textarea', true ); // spit out the metadata in two custom fields echo '<h1 class="entry-title">' . esc_html( $text ) . '</h1>'; echo '<div class="entry-intro">' . esc_html( $textarea ) . '</div>'; } } // inserting custom page content into genesis template add_action( 'genesis_after_entry', 'nb_custom_page' ); // creating custom page content function nb_custom_page() { ?> <!-- you can place aditional page content here --> <?php } // do genesis genesis(); ?>
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The topic ‘How to move a metabox above the main content?’ is closed to new replies.