自定义增加wordpress表情及修改目录

什么都不用说,直接看代码!

//修改表情文件目录,防止更新时被删除。放在函数模板就ok
add_filter('smilies_src','custom_smilies_src',1,10);
function custom_smilies_src ($img_src, $img, $siteurl){
    return $siteurl.'/smilies/'.$img;
}
//自定义表情符号对应的文件名,放在函数模板
if ( !isset( $wpsmiliestrans ) ) {
        $wpsmiliestrans = array(
':a:' => 'ico_a.gif',
':bai:' => 'ico_bai.gif',
':bishi:' => 'ico_bishi.gif',
':chahan:' => 'ico_chahan.gif',
':chengfeng:' => 'ico_chengfeng.gif',
':chijing:' => 'ico_chijing.gif',
':choumei:' => 'ico_choumei.gif',
':dama:' => 'ico_dama.gif',
':e:' => 'ico_e.gif',
        );
}
//结束表情定义
//如果表情比较多直接使用表情文件名为表情对应的标签名
//php代码
$s_path="../../smilies/";//你表情的路径
$s_filedata=glob("$s_path*.gif");
foreach($s_filedata as $s_id => $s_name){
$s_name=str_replace("$s_path","",$s_name);
$s_tage=str_replace(".gif","",$s_name);//如此循环替换你需要的名字就好
$s_tage=str_replace("ico_","",$s_name);
echo "':$s_tage:' => '$s_name'<br>";
}
//接下来生成所需要的图片代码
$s_path="../../smilies/";//你表情的路径
$s_url_path="https://loveyu.org/smilies/";//博客表情对于网址的路径
$s_filedata=glob("$s_path*.gif");
foreach($s_filedata as $s_id => $s_name){
$s_name=str_replace("$s_path","",$s_name);
$s_tage=str_replace(".gif","",$s_name);//如此循环替换你需要的名字就好
$s_tage=str_replace("ico_","",$s_name);
echo "&lt;img src="$s_url_path$s_name" alt=":$s_tage:" onclick='grin(":$s_tage:")' class="wp-smiley-select" />
}
//插入表情的js代码
    <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 = "comment";
        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()">&laquo;&nbsp;less</a></span>';
    }
    function lessSmilies() {
        document.getElementById('wp-smiley-more').style.display = 'none';
        document.getElementById('wp-smiley-toggle').innerHTML = '<a href="javascript:moreSmilies()">more&nbsp;&raquo;</a>';
    }
    </script>


下载:洋葱头表情包

21条评论在“自定义增加wordpress表情及修改目录”

写下你最简单的想法