调用wordpress编辑器wp_editor作用文章评论框

WordPress教程 2508

wordpress 3.3版本开始采用新的编辑器API,支持在任意地方使用wp_editor函数调用wordpress自带的编辑器,比如WP主题后台管理面板、WP文章评论框等,博客吧现在要介绍的是使用wordpress编辑器函数wp_editor替代wp默认的文章评论框。

wp_editor函数参数结构:

1
2
3
4
5
6
7
8
9
10
11
<?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文件,找到评论输入框代码,如:

1
<textarea name="comment" id="comment" rows="6" tabindex="4"></textarea>

替换为:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
	wp_editor( '', comment, 
		$settings = array(
			'quicktags'=> 1,
			//WP默认按钮有strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close 请自行选择
			'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自带的编辑器了!

精品推荐: