2012-01-11 19 views
6

यह सुनकर अच्छा लगा कि सोनी (wordpress3.3) में नया संपादक एपीआई wp_editor() है जो हमें आसानी से हमारे कस्टम फ़ील्ड में संपादक के कई उदाहरणों का उपयोग करने की क्षमता देता है।डिफ़ॉल्ट वर्डप्रेस संपादक को कैसे अनुकूलित करें?

लेकिन मुझे डिफ़ॉल्ट संपादक (मुख्य सामग्री के लिए) को कस्टमाइज़ करने की आवश्यकता थी और यह पता नहीं लगा कि इस फ़ंक्शन के साथ इसे कैसे किया जाए। मुझे अपने नए कस्टम पोस्ट प्रकार के लिए संपादक को कस्टमाइज़ करने की आवश्यकता है जिसे बैनर कहा जाता है जिसके लिए मुझे कम बटन वाले संपादक के आकार को बदलने की आवश्यकता होती है। मुझे पता है कि मैं इसे केवल कस्टम फ़ील्ड का उपयोग करके कर सकता हूं लेकिन किसी कारण से मैं बैनर के विवरण के लिए सामग्री का उपयोग करना चाहता हूं।

अग्रिम में धन्यवाद।

उत्तर

9

मैं डिफ़ॉल्ट संपादक के ऊपर कस्टम मेटाबॉक्स रखने का समाधान ढूंढ रहा था और मुझे अपने पुराने प्रश्न का समाधान मिला है (wp_editor के साथ डिफ़ॉल्ट संपादक को कैसे अनुकूलित करें)!

समाधान डिफ़ॉल्ट संपादक को पहले सेट करना था। फिर सामग्री को रखने के लिए एक और चयापचय बनाएं, फिर नया नया उदाहरण बनाने के लिए wp_editor का उपयोग करें, है ना?

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' 
     ); 
    } 
    } 

इस तरह हमने सामग्री नामक एक नया मेटाबोक्स पंजीकृत किया है। अब संपादक

 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'); 

    } 

अब आप अपने संपादक को पूरी तरह से अनुकूलित कर सकते हैं! इस तरह यह अब दिखता है। आशा है कि यह आपके लिए भी उपयोगी है! enter image description here

+1

के साथ $ सेटिंग्स' पैरामीटर आपको इसे सही उत्तर के रूप में चिह्नित करना चाहिए .. – brasofilo

0

आप कोशिश कर सकते हैं इस Editor आपको अतिरिक्त फ़ील्ड जोड़ सकते हैं जो भी यह, का उपयोग करें और

+0

यह अतिरिक्त प्रकार के साथ भारी था, मुझे यह पसंद नहीं आया, वैसे भी सुझाव के लिए धन्यवाद। –

1

आप एक फिल्टर के साथ संपादक (TinyMCE) अनुकूलित कर सकते हैं स्थापित करने के लिए सरल है दिखाया गया है here। कोड संलग्न स्निपेट:

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'); 

इस कोड को अपने विषय के functions.php फाइल में रखा जाना चाहिए। आप पास की गई सभी कुंजियों को देखने के लिए print_r($in) चाहते हैं (मैंने उनमें से कुछ को यहां छोड़ा है क्योंकि मुझे विश्वास नहीं है कि मैंने ऊपर से लिंक किया गया पृष्ठ अद्यतित है)। आप नवीनतम स्रोत here ब्राउज़ कर सकते हैं। आपको फ़ंक्शन public static function editor_settings($editor_id, $set)

भी आप यह सुनिश्चित करना चाहेंगे कि यह केवल आपके baner post_type के लिए होता है, क्योंकि यह बनाए गए संपादक के सभी उदाहरणों को प्रभावित करेगा।

+0

मैंने यह कोशिश की लेकिन मुझे संपादक आकार (यानी textarea_rows) को बदलने जैसे विकल्पों को नहीं मिला, इसे किशोर बनाते हुए –

+0

आपने अपने प्रारंभिक प्रश्न में wp_editor संदर्भ से लिंक किया - आप इन विकल्पों को ' कुंजी 'textarea_rows' और 'teeny' – chrisn

संबंधित मुद्दे