今天突然想起来,这个也是应该与大家分享的,即我们经常在前台添加独立的文章投稿页面。当然,其实我们在后台也经常添加独立的内容设置部分,这个时候,我们可以调用wordpress自动的编辑器,快速实现编辑器的富文本化。直接上代码:
$settings = array( ?? ?'wpautop' => true, ?? ?'media_buttons' => true, ?? ?'tinymce' => array( ?????? ??? ?'theme_advanced_buttons1' => 'bold,italic,underline,blockquote,|,undo,redo,|,fullscreen', ?????? ??? ?'theme_advanced_buttons2' => '', ?????? ??? ?'theme_advanced_buttons3' => '', ?????? ??? ?'theme_advanced_buttons4' => '' ? ??? ? ), ?? ??? ?'quicktags' => array( ?????? ??? ?'buttons' => 'b,i,ul,ol,li,link,close' ?? ??? ?), ?? ?'media_uploads'=>true ); echo '<form action="" method="post" target="_blank">'; wp_editor('<p>Some more content</p>', 'content_1', $settings ); wp_editor('<p>Some more content</p>', 'content_2', $settings ); echo '<input type="submit" value="Submit" /></form>';
wp_editor的具体使用与参数请看官方文档。上面的代码中,会创建两个文本框,即id="content_1"和id="content_2"的文本框,$setting对它们的表现形式进行的配置,其中media_buttons是让编辑器拥有上传按钮,不过需要有上传权限的用户才能使用。