一、手动添加
为了使评论输入框支持更多的功能,需要进行大量的修改,但是因为WordPress3.3+版本支持wp_Editor函数,我们可以直接调用WordPress自己的编辑器、可视化或HTML,我们可以很容易地在任何地方调用它。那么对文章进行评论时如何调用WordPress编辑器?
wp_editor函数调用格式
<?php wp_editor( $content, $editor_id, $settings = array() ); ?>
如果$content的值对应于注释框的内容,则将其保留为空;$Editor_id对应于id=”comment”;其余设置被放置在$settings数组中。
找到主题评论框代码,
<textarea name=”comment” id=”comment” rows=”6″></textarea>
注意新的版本是在/wp-includes/comment-template.php,找到
echo apply_filters( 'comment_form_field_comment', $field );
替换为
wp_editor( '', 'comment', $settings = array( 'quicktags'=>0, 'tinymce'=>1, 'media_buttons'=>0, 'textarea_rows'=>4 , 'editor_class'=>"textareastyle" ) );
在上述代码中:
quicktags是HTML模式;
tinymce是一个可视模式,值1和0表示它是打开或关闭的;
media_buttons是一个上传文件(只有博客用户登录后才显示,访问者不可见) ;textarea_rows是默认的行数 ;
editor_class是将自定义类添加到WP附带的编辑器Ttextarea区域。
二、增加表情包
直接安装插件,名字叫TinyMCE Smiley Button
然后记得修改一下表情包的样式,CSS的格式,本来的文件是/wp-includes/formatting.php,搜索如下代码(translate_smiley函数)
return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
删除上面的style=”height: 1em; max-height: 1em;”,就可以直接显示表情包实际大小了。
但是也可以通过增加如下自定义CSS样式,实现最大不超过2em高度的表情包显示
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: auto !important;
width: auto !important;
max-height: 2em !important;
margin: 0 0.07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}