new_meta_boxes
单纯的代码备份
- <?php
- $new_meta_boxes =
- array(
- "huilang" => array(
- "name" => "huilang",
- "std" => "",
- "title" => "Huilang:"),
- );
- $new_meta_boxes_1 =
- array(
- "name" => array(
- "name" => "name",
- "std" => "",
- "title" => "Product Name:"),
- );
- function new_meta_boxes() {
- global $post, $new_meta_boxes, $new_meta_boxes_1;
- foreach($new_meta_boxes as $meta_box) {
- $meta_box_value = get_post_meta($post->ID, $meta_box['name'], true);
- if($meta_box_value == "")
- $meta_box_value = get_post_meta($post->ID, $meta_box['name'], true);
- echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
- echo'<h4>'.$meta_box['title'].'</h4>';
- echo wp_editor(get_post_meta($post->ID, $meta_box['name'], true), $meta_box['name'], $settings = array() );
- foreach($new_meta_boxes_1 as $meta_box) {
- $meta_box_huilang = get_post_meta($post->ID, $meta_box['name'].'_huilang', true);
- if($meta_box_huilang == "")
- $meta_box_huilang = $meta_box['std'];
- echo'<div id="'.$meta_box['name'].'_noncename"><input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
- echo'<h4>'.$meta_box['title'].'</h4>';
- echo '<textarea cols="60" rows="3" name="'.$meta_box['name'].'_huilang">'.$meta_box_huilang.'</textarea></div>';
- }
- }
- }
- function create_meta_box() {
- global $theme_name;
- if ( function_exists('add_meta_box') ) {
- add_meta_box( 'new-meta-boxes', '--Huilang.me--, 'new_meta_boxes', 'post', 'normal', 'high' );
- }
- }
- function save_postdata( $post_id ) {
- global $post, $new_meta_boxes, $new_meta_boxes_1;
- foreach($new_meta_boxes as $meta_box) {
- if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
- return $post_id;
- }
- if ( 'page' == $_POST['post_type'] ) {
- if ( !current_user_can( 'edit_page', $post_id ))
- return $post_id;
- }
- else {
- if ( !current_user_can( 'edit_post', $post_id ))
- return $post_id;
- }
- $data = $_POST[$meta_box['name']];
- if(get_post_meta($post_id, $meta_box['name']) == "")
- add_post_meta($post_id, $meta_box['name'], $data, true);
- elseif($data != get_post_meta($post_id, $meta_box['name'], true))
- update_post_meta($post_id, $meta_box['name'], $data);
- elseif($data == "")
- delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true));
- }
- foreach($new_meta_boxes_1 as $meta_box) {
- if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
- return $post_id;
- }
- if ( 'page' == $_POST['post_type'] ) {
- if ( !current_user_can( 'edit_page', $post_id ))
- return $post_id;
- }
- else {
- if ( !current_user_can( 'edit_post', $post_id ))
- return $post_id;
- }
- $data = $_POST[$meta_box['name'].'_huilang'];
- if(get_post_meta($post_id, $meta_box['name'].'_huilang') == "")
- add_post_meta($post_id, $meta_box['name'].'_huilang', $data, true);
- elseif($data != get_post_meta($post_id, $meta_box['name'].'_huilang', true))
- update_post_meta($post_id, $meta_box['name'].'_huilang', $data);
- elseif($data == "")
- delete_post_meta($post_id, $meta_box['name'].'_huilang', get_post_meta($post_id, $meta_box['name'].'_huilang', true));
- }
- }
- add_action('admin_menu', 'create_meta_box');
- add_action('save_post', 'save_postdata');
- ?>
wpautop函数的使用
- <?php echo wpautop(get_post_meta($post->ID, 'huilang',true));?>
- remove_filter( 'the_content', 'wpautop' );
- remove_filter( 'the_excerpt', 'wpautop' );