摘要:用上良心的主题已经有一段时间了,看到他的文章里有表情。唉,不错,有的心情,想法,用一个符号就可以解决了,开始满世界找把表情添加到文章中的办法。

用上良心的主题已经有一段时间了,看到他的文章里有表情。唉,不错,有的心情,想法,用一个符号就可以解决了,开始满世界找把表情添加到文章中的办法。

 

wordpress添加文章表情-空空裤兜

其实,wordpress自带了表情的,只不过非常难看,可以在后台撰写设置将表情符号转化为对应的表情。

这个方法简单,不需要修改文件啥的,自己找到好看的表情覆盖掉wordpress自带的表情即可,缺点就是谁还记得那么多的表情符号啊。 wordpress添加文章表情-空空裤兜

另想他法。费了好大劲,换关键字,在heson这里找到了。代码来自荒野无灯,先上代码看看。

 1: //给主题后台加上表情选项

 2:     if (strpos($_SERVER['REQUEST_URI'], 'post.php') || strpos($_SERVER['REQUEST_URI'], 'post-new.php') || strpos($_SERVER['REQUEST_URI'], 'page-new.php') || strpos($_SERVER['REQUEST_URI'], 'page.php'))

 3: {

 4:     function ihacklog_add_smiley()

 5:     {

 6:         echo <<<EOT

 7:         <script type="text/javascript">

 8:

 9:

 10:         function grin(tag)

 11:         {

 12:         var myField;

 13:         tag = ' ' + tag + ' ';

 14:         if (document.getElementById('content') && document.getElementById('content').style.display != 'none' && document.getElementById('content').type == 'textarea')

 15:         {

 16:             myField = document.getElementById('content');

 17:

 18:             if (document.selection)

 19:             {

 20:             myField.focus();

 21:             sel = document.selection.createRange();

 22:             sel.text = tag;

 23:             myField.focus();

 24:             }

 25:             else

 26:                 if (myField.selectionStart || myField.selectionStart == '0')

 27:                 {

 28:                 var startPos = myField.selectionStart;

 29:                 var endPos = myField.selectionEnd;

 30:                 var cursorPos = endPos;

 31:                 myField.value = myField.value.substring(0, startPos) + tag + myField.value.substring(endPos, myField.value.length);

 32:                 cursorPos += tag.length;

 33:                 myField.focus();

 34:                 myField.selectionStart = cursorPos;

 35:                 myField.selectionEnd = cursorPos;

 36:                 }

 37:                 else

 38:                 {

 39:                 myField.value += tag;

 40:                 myField.focus();

 41:                 }

 42:         }

 43:         else

 44:         {

 45:         tinyMCE.execCommand('mceInsertContent', false, tag);

 46:         }

 47:     }

 48:

 49:     var smiley='<p><a href="javascript:grin(':?:')"><img src="../wp-includes/images/smilies/icon_question.gif" alt="疑惑" /></a><a href="javascript:grin(':razz:')"><img src="../wp-includes/images/smilies/icon_razz.gif" alt="冷笑" /></a><a href="javascript:grin(':sad:')"><img src="../wp-includes/images/smilies/icon_sad.gif" alt="伤心" /></a><a href="javascript:grin(':evil:')"><img src="../wp-includes/images/smilies/icon_evil.gif" alt="邪恶" /></a><a href="javascript:grin(':!:')"><img src="../wp-includes/images/smilies/icon_exclaim.gif" alt="感叹" /></a><a href="javascript:grin(':smile:')"><img src="../wp-includes/images/smilies/icon_smile.gif" alt="微笑" /></a><a href="javascript:grin(':oops:')"><img src="../wp-includes/images/smilies/icon_redface.gif" alt="红脸" /></a><a href="javascript:grin(':grin:')"><img src="../wp-includes/images/smilies/icon_biggrin.gif" alt="咧嘴笑" /></a><a href="javascript:grin(':eek:')"><img src="../wp-includes/images/smilies/icon_surprised.gif" alt="吃惊" /></a><a href="javascript:grin(':shock:')"><img src="../wp-includes/images/smilies/icon_eek.gif" alt="惊讶" /></a><a href="javascript:grin(':???:')"><img src="../wp-includes/images/smilies/icon_confused.gif" alt="困惑" /></a><a href="javascript:grin(':cool:')"><img src="../wp-includes/images/smilies/icon_cool.gif" alt="耍酷" /></a><a href="javascript:grin(':lol:')"><img src="../wp-includes/images/smilies/icon_lol.gif" alt="大笑" /></a><a href="javascript:grin(':mad:')"><img src="../wp-includes/images/smilies/icon_mad.gif" alt="抓狂" /></a><a href="javascript:grin(':twisted:')"><img src="../wp-includes/images/smilies/icon_twisted.gif" alt="痛苦" /></a><a href="javascript:grin(':roll:')"><img src="../wp-includes/images/smilies/icon_rolleyes.gif" alt="转眼珠" /></a><a href="javascript:grin(':wink:')"><img src="../wp-includes/images/smilies/icon_wink.gif" alt="眨眼" /></a><a href="javascript:grin(':idea:')"><img src="../wp-includes/images/smilies/icon_idea.gif" alt="好主意" /></a><a href="javascript:grin(':arrow:')"><img src="../wp-includes/images/smilies/icon_arrow.gif" alt="" /></a><a href="javascript:grin(':neutral:')"><img src="../wp-includes/images/smilies/icon_neutral.gif" alt="自然" /></a><a href="javascript:grin(':cry:')"><img src="../wp-includes/images/smilies/icon_cry.gif" alt="哭" /></a><a href="javascript:grin(':mrgreen:')"><img src="../wp-includes/images/smilies/icon_mrgreen.gif" alt="绿脸先生" /></a></p>';

 50:             jQuery('#quicktags').before(smiley);

 51:

 52: </script>

 53: EOT;

 54:         }

 55:

 56:     add_action('admin_footer','ihacklog_add_smiley');}

将代码添加到主题的functions.php文件中。进后台编辑器看看效果吧。直接在编辑器就可以添加表情,哇咔咔。

wordpress添加文章表情-空空裤兜

代码里有表情的路径,应该可以改的,不知道为什么我改了路径后台编辑器就不显示了,但是文章中可以显示,可能是我把主题中的所有图片搬到图床的原因吧~算了,不整了,直接用FTP覆盖掉原来的表情文件也不是神马难事。

再得瑟一下~~ wordpress添加文章表情-空空裤兜 wordpress添加文章表情-空空裤兜