一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Wordpress 修改custom-smilies显示表情位置

时间:2013-07-13 编辑:简简单单 来源:一聚教程网

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 = ’ –>

img.wp-smiley-select {cursor: pointer;}

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 = “”;

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 = ’« less’;

}

 

function lessSmilies() {

document.getElementById(’wp-smiley-more’).style.display = ’none’;

document.getElementById(’wp-smiley-toggle’).innerHTML = ’more »’;

}

’;

 

$smilies = cs_load_existing_smilies();

$url = clcs_get_smilies_path();

$list = get_option(‘cs_list’); 

 

if ($list == ”) {

foreach ($smilies as $k => $v) {

$content .= “ ”;

}

} else {

$display = explode(‘,’, $list);

$smilies = array_flip($smilies);

foreach ($display as $v) {

$v = trim($v);

$content .= “ ”;

unset($smilies[$v]); 

}

$content .= ’’;

foreach ($smilies as $k => $v) {

$content .= “ ”;

}

$content .= ’ more »’;

}

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’), ‘*’ );这句的前面,添加一行内容:$content_me = cs_print_smilies2(); 接着在第1534行,也就是’comment_field’ => ‘

……这行,替换成

‘comment_field’ => ’’ . _x( ’Comment’, ’noun’ ) . ’
’.$content_me.’

’, 

 保存上传上服务器,刷新下看看,是不是表情位置已经放到前面

热门栏目