WordPress 3.3 版本開始採用新的編輯器 API,支援在任意地方使用 wp_editor 函式呼叫 WordPress 自帶的編輯器,比如 WP 主題後臺管理面板、 WP 文
章評論框等,部落格吧現在要介紹的是使用 WordPress 編輯器函式 wp_editor 替代 wp 預設的文章評論框。
wp_editor 函式引數結構:
<?php wp_editor($content, $editor_id, $settings = array( 'quicktags'=>1, 'tinymce'=>0, 'media_buttons'=>0, 'textarea_rows'=>4, 'editor_class'=>"textareastyle" ) ); ?>
quicktags 是 HTML 模式。
tinymce 是視覺化模式。 (使用視覺化模式還要再進一步給視覺化加上適合主題的 css 樣式)
media_buttons 是上傳檔案 (對訪客不可見)
textarea_rows 是預設行數
editor_class 是給 WP 自帶的編輯器 textarea 區域加上自定義 class
編輯當前主題目錄中的 comments.php 檔案,找到評論輸入框程式碼,如:
<textarea name="comment" id="comment" rows="6" tabindex="4"></textarea>
替換為:
<?php wp_editor( '', comment, $settings = array( 'quicktags'=> 1, //WP 預設按鈕有 strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close 請自行選擇 by www.weixiaoduo.com 'quicktags'=> array('buttons' => 'strong,em,link,del,img,ul,ol,li,code,spell,close',), 'tinymce'=>0, 'media_buttons'=>0, 'textarea_rows'=>4, 'editor_class'=>"textareastyle" ) ); ?>
wp_editor 中 $content 的值對應評論框的內容,留空就可以了;$editor_id 對應 id=」comment」;
儲存之後,進入文章頁面,評論框就會變成 WordPress 自帶的編輯器了!