Wordpress 修改custom-smilies显示表情位置
custom-smilies是一款实现评论时可以添加表情的插件,安装方法我就不说了,网上大把,大家可以去搜搜,我要说的是,怎么修改表情的显示位置,我用的是prowerv4主题,custom-smilies可以默认添加表情在comment_form 后面,但是从使用习惯而已,大家都是习惯表情在输入框的上面(–!至少我是这样认为).
好了,转正题,首先你先在找到 wp-content/theme/{你使用的主题}/comments.php 看看,是调用comment_form()这个函数生成的回复框还是直接用html生成的,作者我这里是调用comment_form()的,所以就比较麻烦,思路很简单,先找到comment_form()这个函数,在这个函数里面找到你想插入的位置,把表情的内容生成到这里,当调用comment_form()函数时,就一起把表情和回复框一起生成.
OK,第一步,打开 wp-content/plugin/custom-smilies-ce/comment.inc.php,在 if (array_key_exists(‘use_action_comment_form’,$clcs_options) && $clcs_options['use_action_comment_form'] == 1) 的前面添加以下代码:
-
- function clcs_print_smilies2($comment_textarea = ’comment’) {
-
-
- $content = ’<!– Custom Smilies - Version <?php echo CLCSVER; ?> –>
- <style type=“text/css”>
- img.wp-smiley-select {cursor: pointer;}
- </style>
- <script type=“text/javascript”>
- function grin(tag) {
- if (typeof tinyMCE != ’undefined’) {
- grin_tinymcecomments(tag);
- } else {
- grin_plain(tag);
- }
- }
- function grin_tinymcecomments(tag) {
- tinyMCE.execCommand(’mceInsertContent’, false, ’ ’ + tag + ’ ’);
- }
-
- function grin_plain(tag) {
- var myField;
- var myCommentTextarea = “<?php echo $comment_textarea; ?>”;
- tag = ’ ’ + tag + ’ ’;
- if (document.getElementById(myCommentTextarea) && document.getElementById(myCommentTextarea).type == ’textarea’) {
- myField = document.getElementById(myCommentTextarea);
- } else {
- return false;
- }
- if (document.selection) {
- myField.focus();
- sel = document.selection.createRange();
- sel.text = tag;
- myField.focus();
- }
- else if (myField.selectionStart || myField.selectionStart == ’0’) {
- var startPos = myField.selectionStart;
- var endPos = myField.selectionEnd;
- var cursorPos = endPos;
- myField.value = myField.value.substring(0, startPos)
- + tag
- + myField.value.substring(endPos, myField.value.length);
- cursorPos += tag.length;
- myField.focus();
- myField.selectionStart = cursorPos;
- myField.selectionEnd = cursorPos;
- }
- else {
- myField.value += tag;
- myField.focus();
- }
- }
-
- function moreSmilies() {
- document.getElementById(’wp-smiley-more’).style.display = ’inline’;
- document.getElementById(’wp-smiley-toggle’).innerHTML = ’<a href=“javascript:lessSmilies()”>« less</a></span>’;
- }
-
- function lessSmilies() {
- document.getElementById(’wp-smiley-more’).style.display = ’none’;
- document.getElementById(’wp-smiley-toggle’).innerHTML = ’<a href=“javascript:moreSmilies()”>more »</a>’;
- }
- </script>’;
- $smilies = cs_load_existing_smilies();
- $url = clcs_get_smilies_path();
- $list = get_option(‘cs_list’);
-
- if ($list == ”) {
- foreach ($smilies as $k => $v) {
- $content .= “<img src=’{$url}/{$k}’ alt=’{$v}’ onclick=’grin(”{$v}”)’ class=’wp-smiley-select’ /> ”;
- }
- } else {
- $display = explode(‘,’, $list);
- $smilies = array_flip($smilies);
- foreach ($display as $v) {
- $v = trim($v);
- $content .= “<img src=’{$url}/{$smilies[$v]}’ alt=’{$v}’ onclick=’grin(”{$v}”)’ class=’wp-smiley-select’ /> ”;
- unset($smilies[$v]);
- }
- $content .= ’<span id=“wp-smiley-more” style=“display:none”>’;
- foreach ($smilies as $k => $v) {
- $content .= “<img src=’{$url}/{$v}’ alt=’{$k}’ onclick=’grin(”{$k}”)’ class=’wp-smiley-select’ /> ”;
- }
- $content .= ’</span> <span id=“wp-smiley-toggle”><a href=“javascript:moreSmilies()”>more »</a></span>’;
- }
- return $content;
- }
- function cs_print_smilies2() {
- global $clcs_options;
- return clcs_print_smilies2($clcs_options['comment_textarea']);
- }
-
第二步,打开wp-include/comment-template.php,在第1530行那里,也就是$required_text = sprintf( ‘ ‘ . __(‘Required fields are marked %s’), ‘<span class=”required”>*</span>’ );这句的前面,添加一行内容:$content_me = cs_print_smilies2(); 接着在第1534行,也就是’comment_field’ => ‘<p class=”comment-form-comment”>……这行,替换成
‘comment_field’ => ’<p class=“comment-form-comment”><label for=“comment”>’ . _x( ’Comment’, ’noun’ ) . ’</label><br>’.$content_me.’<textarea id=“comment” name=“comment” cols=“45″ rows=“8″ aria-required=“true”></textarea></p>’,
保存上传上服务器,刷新下看看,是不是表情位置已经放到前面.