2012-01-11 37 views
6

tốt khi biết rằng Sony (wordpress3.3) có biên tập api mới wp_editor() cung cấp cho chúng ta khả năng sử dụng nhiều trường hợp của các biên tập viên trong các lĩnh vực tùy chỉnh của chúng tôi một cách dễ dàng.Làm thế nào để tùy chỉnh trình soạn thảo wordpress mặc định?

Nhưng tôi cần phải để tùy chỉnh soạn thảo mặc định (đối với nội dung chính) và không thể tìm ra cách để làm điều đó với chức năng này. Tôi cần tùy chỉnh trình chỉnh sửa cho loại bài đăng tùy chỉnh mới của tôi được gọi là lệnh cấm mà tôi cần thay đổi kích thước của trình chỉnh sửa bằng các nút ít hơn. Tôi biết tôi có thể làm điều đó bằng cách sử dụng một lĩnh vực tùy chỉnh thay vì nhưng đối với một số lý do tôi muốn sử dụng nội dung cho các mô tả của các biểu ngữ.

Cảm ơn bạn trước.

Trả lời

9

tôi đang tìm kiếm một giải pháp để đặt Metabox tùy chỉnh trên trình biên tập mặc định và tôi đã tìm thấy giải pháp cho câu hỏi cũ của tôi (làm thế nào để tùy chỉnh editor mặc định với wp_editor)!

Giải pháp là bỏ đặt soạn thảo mặc định đầu tiên. Sau đó tạo một metabox khác để đặt nội dung, sau đó sử dụng wp_editor để tạo mới cá thể mới của nó, đơn giản phải không?

add_action('add_meta_boxes', 'page_meta_boxes'); 
public function page_meta_boxes() 
{ 

    global $_wp_post_type_features; 
      //ive defined my other metaboxes first with higher priority 
    add_meta_box(
     $id  = 'page_heading_meta_box', 
     $title = __('Heading'), 
     $callback = array(&$this,'render_page_heading_metabox'), 
     $post_type = 'page', 
     $context = 'normal', 
     $priority = 'core' 
     ); 
    add_meta_box(
     $id  = 'page_description_meta_box', 
     $title = __('Description'), 
     $callback = array(&$this,'render_page_description_metabox'), 
     $post_type = 'page', 
     $context = 'normal', 
     $priority = 'core' 
     ); 
    //check for the required post type page or post or <custom post type(here article) 
    if (isset($_wp_post_type_features['article']['editor']) && $_wp_post_type_features['post']['editor']) { 
     unset($_wp_post_type_features['article']['editor']); 
     add_meta_box(
      'wsp_content', 
      __('Content'), 
      array(&$this,'content_editor_meta_box'), 
      'article', 'normal', 'core' 
     ); 
    } 
    if (isset($_wp_post_type_features['page']['editor']) && $_wp_post_type_features['page']['editor']) { 
     unset($_wp_post_type_features['page']['editor']); 
     add_meta_box(
      'wsp_content', 
      __('Content'), 
      array(&$this,'content_editor_meta_box'), 
      'page', 'normal', 'low' 
     ); 
    } 
    } 

Bằng cách này, chúng tôi đã đăng ký một Metabox mới gọi là nội dung. Bây giờ là lúc để đặt trình chỉnh sửa

 function content_editor_meta_box($post) 
    { 
     $settings = array(
      #media_buttons 
      #(boolean) (optional) Whether to display media insert/upload buttons 
      #Default: true 
      'media_buttons' => true, 

      #textarea_name 
      #(string) (optional) The name assigned to the generated textarea and passed parameter when the form is submitted. (may include [] to pass data as array) 
      #Default: $editor_id 
      'textarea_name'=>'content', 

      #textarea_rows 
      #(integer) (optional) The number of rows to display for the textarea 
      #Default: get_option('default_post_edit_rows', 10) 

      #tabindex 
      #(integer) (optional) The tabindex value used for the form field 
      #Default: None 
      'tabindex' => '4' 

      #editor_css 
      #(string) (optional) Additional CSS styling applied for both visual and HTML editors buttons, needs to #include <style> tags, can use "scoped" 
      #Default: None 

      #editor_class 
      #(string) (optional) Any extra CSS Classes to append to the Editor textarea 
      #Default: 

      #teeny 
      #(boolean) (optional) Whether to output the minimal editor configuration used in PressThis 
      #Default: false 

      #dfw 
      #(boolean) (optional) Whether to replace the default fullscreen editor with DFW (needs specific DOM elements #and css) 
      #Default: false 

      #tinymce 
      #(array) (optional) Load TinyMCE, can be used to pass settings directly to TinyMCE using an array() 
      #Default: true 

      #quicktags 
      #(array) (optional) Load Quicktags, can be used to pass settings directly to Quicktags using an array() 
      #Default: true 
     ); 
     wp_editor($post->post_content,'content'); 

    } 

Bây giờ bạn hoàn toàn có thể tùy chỉnh trình chỉnh sửa của mình! Đây là cách nó trông bây giờ. Hy vọng nó cũng hữu ích cho bạn! enter image description here

+1

Bạn nên đánh dấu tham số này là câu trả lời đúng .. – brasofilo

0

Bạn có thể thử Editor này mà bạn có thể thêm các trường khác cũng có thể nó là đơn giản để sử dụng và cài đặt

+0

Đó là loại nặng, với các bảng phụ, tôi không thích điều đó, dù sao nhờ đề nghị. –

1

Bạn có thể tùy chỉnh các biên tập viên (TinyMCE) với một bộ lọc, như here. Đoạn mã được đính kèm:

function myformatTinyMCE($in) 
{ 
$in['plugins']='inlinepopups,tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpfullscreen'; 
$in['wpautop']=true; 
$in['apply_source_formatting']=false; 
$in['theme_advanced_buttons1']='formatselect,forecolor,|,bold,italic,underline,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,|,wp_fullscreen,wp_adv'; 
$in['theme_advanced_buttons2']='pastetext,pasteword,removeformat,|,charmap,|,outdent,indent,|,undo,redo'; 
$in['theme_advanced_buttons3']=''; 
$in['theme_advanced_buttons4']=''; 
return $in; 
} 
add_filter('tiny_mce_before_init', 'myformatTinyMCE'); 

Mã này phải được đặt trong tệp functions.php của chủ đề của bạn. Bạn có thể muốn print_r($in) để xem tất cả các khóa đã được chuyển (Tôi đã bỏ qua một số khóa ở đây vì tôi không tin rằng trang mà tôi đã liên kết ở trên là cập nhật). Bạn có thể duyệt nguồn mới nhất here. Bạn cũng sẽ tìm thấy các bộ lọc mà bạn đang tìm kiếm theo chức năng public static function editor_settings($editor_id, $set)

Ngoài ra, bạn cũng có thể muốn đảm bảo rằng điều này chỉ xảy ra cho baner post_type của bạn, vì điều này sẽ ảnh hưởng đến tất cả các phiên bản của trình chỉnh sửa được tạo.

+0

tôi đã cố gắng này, nhưng tôi đã không tìm thấy bất kỳ tùy chọn như thay đổi kích thước editor (tức textarea_rows), làm cho nó teeny, vv –

+0

Bạn liên kết với tài liệu tham khảo wp_editor trong câu hỏi ban đầu của bạn - bạn có thể sửa đổi các tùy chọn thông qua ' Tham số $ settings' với các phím 'textarea_rows' và' teeny' – chrisn

Các vấn đề liên quan