为wordpress主题添加评论表情

1.创建smiley.php:

<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(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_mrgreen.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':evil:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_evil.gif" title="抠鼻" alt="抠鼻" /></a>  
<a onclick="javascript:grin(':shock:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_eek.gif" title="吓到了" alt="吓到了" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_exclaim.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_idea.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_lol.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':oops:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_redface.gif" title="可爱" alt="可爱" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_mad.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_razz.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_rolleyes.gif" title="嘿黑" alt="嘿黑" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_smile.gif" title="嘿黑" alt="嘿黑" /></a>  
  
<a onclick="javascript:grin(':?:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_question.gif" title="疑问" alt="疑问" /></a>  
<a onclick="javascript:grin(':sad:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_sad.gif" title="伤心" alt="伤心" /></a>  
<a onclick="javascript:grin(':grin:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_biggrin.gif" title="奸笑" alt="奸笑" /></a>  
<a onclick="javascript:grin(':eek:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_surprised.gif" title="震惊" alt="震惊" /></a>  
<a onclick="javascript:grin(':???:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_confused.gif" title="撇嘴" alt="撇嘴" /></a>  
<a onclick="javascript:grin(':cool:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_cool.gif" title="酷" alt="酷" /></a>  
<a onclick="javascript:grin(':twisted:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_twisted.gif" title="狂怒" alt="狂怒" /></a>  
<a onclick="javascript:grin(':wink:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_wink.gif" title="鼓掌" alt="鼓掌" /></a>  
<a onclick="javascript:grin(':arrow:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_arrow.gif" title="⊙﹏⊙b汗" alt="⊙﹏⊙b汗" /></a>   
<a onclick="javascript:grin(':neutral:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_neutral.gif" title="鄙视" alt="鄙视" /></a>  
<a onclick="javascript:grin(':mrgreen:')"><img src="/wp-content/themes/当前主题名/img/smilies/icon_cry.gif" title="嘿黑" alt="嘿黑" /></a>  
  
</div>  

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'); ?>  

参考文章:
xiu主题添加QQ评论表情
http://t.cn/RwhjOwG


 继续浏览关于 技术有趣WordPress 的文章

 本文最后更新于 2019/07/21 03:06:05,可能因经年累月而与现状有所差异

 引用转载请注明:icret > 教程 > 为wordpress主题添加评论表情