xiu主题添加QQ评论表情

Author: 陌小雨Date: 2015-02-05View: 88

1、将下面代码保存到smiley.php文件中,注意编码格式为utf-8,然后上传到主题文件夹下。

<script type="text/javascript" language="javascript">   
/* <![CDATA[ */  
    function grin(tag) {   
        var myField;   
        tag = ' ' + tag + ' ';   
        if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {   
            myField = document.getElementById('comment');   
        } 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();   
        }   
    }   
/* ]]> */  
</script>   
<div id="smilelink">   
<a onclick="javascript:grin('::')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_question.gif" title="疑问" alt="疑问" /></a>   
<a onclick="javascript:grin(':sad:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_sad.gif" title="伤心" alt="伤心" /></a>   
<a onclick="javascript:grin(':evil:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_evil.gif" title="抠鼻" alt="抠鼻" /></a>   
<a onclick="javascript:grin(':oops:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_redface.gif" title="可爱" alt="可爱" /></a>   
<a onclick="javascript:grin(':grin:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_biggrin.gif" title="奸笑" alt="奸笑" /></a>   
<a onclick="javascript:grin(':eek:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_surprised.gif" title="震惊" alt="震惊" /></a>   
<a onclick="javascript:grin(':shock:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_eek.gif" title="吓到了" alt="吓到了" /></a>   
<a onclick="javascript:grin('::')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_confused.gif" title="撇嘴" alt="撇嘴" /></a>   
<a onclick="javascript:grin(':cool:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_cool.gif" title="酷" alt="酷" /></a> 
<a onclick="javascript:grin(':twisted:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_twisted.gif" title="狂怒" alt="狂怒" /></a>   
<a onclick="javascript:grin(':wink:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_wink.gif" title="鼓掌" alt="鼓掌" /></a>   
<a onclick="javascript:grin(':arrow:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_arrow.gif" title="⊙﹏⊙b汗" alt="⊙﹏⊙b汗" /></a>   
<a onclick="javascript:grin(':neutral:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_neutral.gif" title="鄙视" alt="鄙视" /></a>   
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/xiu2.1/images/smilies/icon_mrgreen.gif" title="嘿黑" alt="嘿黑" /></a>   
</div>

注意:如果你重新命名过主题文件夹,需要将上述代码中的主题文件夹名xiu2.1修改为你自己的主题文件夹名

2、修改主题文件夹comment.php,找到下面代码

<!-- <span data-type="comment-insert-smilie" class="muted comt-smilie"><i class="icon-thumbs-up icon12"></i> 表情</span> -->

替换为:

<?php include(TEMPLATEPATH . '/smiley.php'); ?>

3、QQ表情包下载和上传

QQ表情包百度网盘下载

使用方法:先删除主题文件images/smilies文件夹下的所有表情,然后将下载好的表情包解压,将解压后的所有表情上传到主题文件images/smilies文件夹下即可。

2017-9-2日更新:

wordpress 4.2新增了emoji表情,但由于emoji表情是调用的被墙的外部链接,导致表情无法显示。我们需要禁用掉wordpress自带的emoji表情,并调用自定义的表情。

下载文件patch_to_4.2.php,放到xiu主题根目录,然后在functions.php中调用该文件即可。

include("patch_to_4.2.php");
你的二维码名字
请输入验证码查看内容
验证码:
微信扫码,回复关键字“92wp”获取验证码即可查看