study

学习文章

zw-1988.com

home > 学习文章 > 放到function 在默认投稿里写个选项

2023.6.07 放到function 在默认投稿里写个选项

放到function 在默认投稿里写个选项 radio


$new_meta_boxes =    
array(   
   
    "radio" => array(   
        "name" => "_meta_radio",   
        "std" => 1,      
        "title" => "",   
        "buttons" => array('off','on'),   
        "type"=>"radio"),   

           
);  
function new_meta_boxes() {   
    global $post, $new_meta_boxes;   
    foreach($new_meta_boxes as $meta_box) {   
          
        $meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);   
        if($meta_box_value != "")      
            $meta_box['std'] = $meta_box_value; 
           
        echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';   
          
        switch ( $meta_box['type'] ){   
              
            case 'radio':   
               
                $counter = 1;   
                foreach( $meta_box['buttons'] as $radiobutton ) {   
                    $checked ="";   
                    if(isset($meta_box['std']) && $meta_box['std'] == $counter) {   
                        $checked = 'checked = "checked"';   
                    }   
                    echo '<label for="rec_item" style="margin-right:15px;"><input '.$checked.' type="radio" class="kcheck" value="'.$counter.'" name="'.$meta_box['name'].'_value"/>'.$radiobutton.'</label>';   
                    $counter++;   
                }   
                break;   
         
               
        }             
    }      
}  
function create_meta_box() {      
    global $theme_name;      
     
    if ( function_exists('add_meta_box') ) {      
        add_meta_box( 'new-meta-boxes', 'モーダル', 'new_meta_boxes', 'post', 'normal', 'high' );      
    }      
}  
function save_postdata( $post_id ) {      
    global $post, $new_meta_boxes;      
     
    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'].'_value'];      
     
        if(get_post_meta($post_id, $meta_box['name'].'_value') == "")      
            add_post_meta($post_id, $meta_box['name'].'_value', $data, true);      
        elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))      
            update_post_meta($post_id, $meta_box['name'].'_value', $data);      
        elseif($data == "")      
            delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));      
    }      
}  
add_action('admin_menu', 'create_meta_box');      
add_action('save_post', 'save_postdata');  

$ashu_eitor = get_post_meta($post->ID, "_meta_radio_value", true);  
<!--?php get_header();
$category = get_the_category();
$category_name = get_category($category)--->name;
$cat_parent_id = $category[0]->category_parent;
$cat_parents_id = get_category($cat_parent_id)->category_parent;
$cat_parents_name = get_category($cat_parents_id)->name;
$ashu_eitor = get_post_meta($post->ID, "_meta_radio_value", true);  
if($ashu_eitor=='2'){
	echo '<script>var meilleur_products_link_js = "need_auth";</script>';
}
?>
«
相关文章
wordpress (25)java script (9)tool (8)css (2)攻略 (1)第一次人体 (1)插件 (1)ECharts (1)food (1)雪糕 (1)动画 (1)book (1)标签云 (1)生活 (1)一言难尽的画稿 (1)
辽ICP备16002031号

Copyright © 2016 - 2020 1988-zw.com