How To Add Secondary Content to WordPress Pages (or Posts)
There may be few occasions where you like to have secondary content in your pages or posts on your WordPress website. We have a snippet that solves the issue. With this snippet below you can add a secondary blurb to a WordPress page/post. This is very useful if your theme has a two colounm layout and you’d like a dedicated rich text-editor for each.
To output the content of the secondary blurb in our theme, use <?php echo yourplugin_secondary_blurb() ?>
in your desired template page (ie: page.php or single.php) and place the following in functions.php:
<? //call our hooks add_action('admin_init', 'yourplugin_metabox'); add_action('save_post', 'yourplugin_metabox_save'); //return the custom blurb function yourplugin_secondary_blurb($id = '') { $id = (empty($id)) ? get_the_ID() : intval($id); $custom = get_post_custom($id); return @$custom['secondary_blurb'][0]; } // add metabox to 'page' post type // use 'post' for posts or array('page','post') for multi function yourplugin_metabox() { global $hys; if ( current_user_can('manage_options') ) add_meta_box( 'secondary_blurb_box_id', __('Secondary Blurb', 'yourplugin_sec_blurb' ), 'secondary_blurb_box', 'page' ); } //secondary blurb metabox HTML function secondary_blurb_box() { global $post; echo '<input type="hidden" name="yourplugin_noncename"'. ' id="yourplugin_noncename" value="' . wp_create_nonce( 'aunqiueyourpluginid' ) . '" /> <style type="text/css"> #ed_toolbar { display:none; } </style><div>'; the_editor(yourplugin_secondary_blurb(), "secondary_blurb"); echo "</div>"; } // save the secondary blurb value. verify and permission function yourplugin_metabox_save( $post_id ) { global $hys; if (!isset($_POST['yourplugin_noncename']) || !wp_verify_nonce( $_POST['yourplugin_noncename'], 'aunqiueyourpluginid' )) return $post_id; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } //save the secondary blurb text if applic.. if (isset($_POST['secondary_blurb'])) { update_post_meta($post_id,'secondary_blurb',$_POST['secondary_blurb']) or add_post_meta($post_id,'secondary_blurb',$_POST['secondary_blurb']); } } ?>