如何删除整个发布块并仅显示发布按钮

时间:2013-12-04 13:19:23

标签: php wordpress

使用register_post_type我正在创建一个post_type所以在“添加新”页面右侧我不想要整个发布块,我只想要发布按钮。我怎么能这样做。请帮帮我,我的代码是 -

// Create Brand Management
    add_action('init', 'manage_brand');
    function manage_brand() {
        register_post_type('brand', array(
            'labels' => array(
                'name' => 'Manage Brand',
                'singular_name' => 'Manage Brand',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New Brand',
                'edit' => 'Edit',
                'edit_item' => 'Edit Brand',
                'new_item' => 'New Brand',
                'view' => 'View',
                'view_item' => 'View Brand',
                'search_items' => 'Search Brand',
                'not_found' => 'No Brand',
                'not_found_in_trash' => 'No Brand found in Trash',
                'parent' => 'Parent News Brand'
            ),
            'public' => true,
            'menu_position' => 100,
            'supports' => array('title','thumbnail'),
            'taxonomies' => array(''),

    'menu_icon' => plugins_url('images/adv-.png', __FILE__),
        'has_archive' => true,
    )
    );

和创建meta_box的代码是 -

![//add meta data for brand
add_action('admin_init', 'brand_register_meta_boxes');

function brand_register_meta_boxes() {
if (!class_exists('RW_Meta_Box'))
        return;
    $prefix = 'brand_';

    $meta_boxes\[\] = array(
       'title' => 'Add Brand',
        'pages' => array('brand'),

        'fields' => array(

            array(
            'name' => __( 'Brand Name', 'rwmb' ),
            'desc' => __( 'Add Brand Name', 'rwmb' ),
            'id'   => "{$prefix}code",
            'type' => 'text',
            'required' => true,

            ), 

        )
    );     
        foreach ($meta_boxes as $meta_box) {
        new RW_Meta_Box($meta_box);
    }

}
    }![enter image description here][1]

1 个答案:

答案 0 :(得分:0)

你可以用jQuery做到这一点。 首先,使用保存按钮隐藏元框:

jQuery('#submitdiv:has(#publish)').css({'display':'none'});

其次,只显示你想要的按钮,例如在特色图像元数据

之前
jQuery('#postimagediv').append('<input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="Update">');

将此代码包装在php函数中,该函数将在admin_head hook之后初始化:

<?php 
function my_custom_admin_head(){

echo '<script>
        jQuery(document).ready(function(){
        jQuery('#submitdiv:has(#publish)').css({'display':'none'});
        jQuery('#postimagediv').append('<input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="Update">');
});
</script>';

}
add_action('admin_head', 'my_custom_admin_head');
?>