当前位置:首页 > CMS教程 > WordPress > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2014-03-19 13:38:53 浏览: 评论:0 

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) 的前面添加以下代码:

  1. //——-自增内容—— 
  2. function clcs_print_smilies2($comment_textarea = ’comment’) { 
  3.  
  4.  
  5. $content = ’<!– Custom Smilies - Version <?php echo CLCSVER; ?> –> 
  6. <style type=“text/css”> 
  7. img.wp-smiley-select {cursor: pointer;} 
  8. </style> 
  9. <script type=“text/javascript”> 
  10. function grin(tag) { 
  11. if (typeof tinyMCE != ’undefined’) { 
  12. grin_tinymcecomments(tag); 
  13. } else { 
  14. grin_plain(tag); 
  15. } 
  16. } 
  17. function grin_tinymcecomments(tag) { 
  18. tinyMCE.execCommand(’mceInsertContent’, false, ’ ’ + tag + ’ ’); 
  19. } 
  20.  
  21. function grin_plain(tag) { 
  22. var myField; 
  23. var myCommentTextarea = “<?php echo $comment_textarea; ?>”; 
  24. tag = ’ ’ + tag + ’ ’; 
  25. if (document.getElementById(myCommentTextarea) && document.getElementById(myCommentTextarea).type == ’textarea’) { 
  26. myField = document.getElementById(myCommentTextarea); 
  27. } else { 
  28. return false; 
  29. } 
  30. if (document.selection) { 
  31. myField.focus(); 
  32. sel = document.selection.createRange(); 
  33. sel.text = tag; 
  34. myField.focus(); 
  35. } 
  36. else if (myField.selectionStart || myField.selectionStart == ’0’) { 
  37. var startPos = myField.selectionStart; 
  38. var endPos = myField.selectionEnd; 
  39. var cursorPos = endPos; 
  40. myField.value = myField.value.substring(0, startPos) 
  41. + tag 
  42. + myField.value.substring(endPos, myField.value.length); 
  43. cursorPos += tag.length; 
  44. myField.focus(); 
  45. myField.selectionStart = cursorPos; 
  46. myField.selectionEnd = cursorPos; 
  47. } 
  48. else { 
  49. myField.value += tag; 
  50. myField.focus(); 
  51. } 
  52. } 
  53.  
  54. function moreSmilies() { 
  55. document.getElementById(’wp-smiley-more’).style.display = ’inline’; 
  56. document.getElementById(’wp-smiley-toggle’).innerHTML = ’<a href=“javascript:lessSmilies()”>&laquo;&nbsp;less</a></span>’; 
  57. } 
  58.  
  59. function lessSmilies() { 
  60. document.getElementById(’wp-smiley-more’).style.display = ’none’; 
  61. document.getElementById(’wp-smiley-toggle’).innerHTML = ’<a href=“javascript:moreSmilies()”>more&nbsp;&raquo;</a>’; 
  62. } 
  63. </script>’; 
  64. $smilies = cs_load_existing_smilies(); 
  65. $url = clcs_get_smilies_path(); 
  66. $list = get_option(‘cs_list’);  
  67.  
  68. if ($list == ”) { 
  69. foreach ($smilies as $k => $v) { 
  70. $content .= “<img src=’{$url}/{$k}’ alt=’{$v}’ onclick=’grin(”{$v}”)’ class=’wp-smiley-select’ /> ”; 
  71. } 
  72. } else { 
  73. $display = explode(‘,’, $list); 
  74. $smilies = array_flip($smilies); 
  75. foreach ($display as $v) { 
  76. $v = trim($v); 
  77. $content .= “<img src=’{$url}/{$smilies[$v]}’ alt=’{$v}’ onclick=’grin(”{$v}”)’ class=’wp-smiley-select’ /> ”; 
  78. unset($smilies[$v]);  
  79. } 
  80. $content .= ’<span id=“wp-smiley-more” style=“display:none”>’; 
  81. foreach ($smilies as $k => $v) { 
  82. $content .= “<img src=’{$url}/{$v}’ alt=’{$k}’ onclick=’grin(”{$k}”)’ class=’wp-smiley-select’ /> ”; 
  83. } 
  84. $content .= ’</span> <span id=“wp-smiley-toggle”><a href=“javascript:moreSmilies()”>more&nbsp;&raquo;</a></span>’; 
  85. } 
  86. return $content; 
  87. } 
  88. function cs_print_smilies2() { 
  89. global $clcs_options; 
  90. return clcs_print_smilies2($clcs_options['comment_textarea']); 
  91. } 
  92. //——-结束——– 

第二步,打开wp-include/comment-template.php,在第1530行那里,也就是$required_text = sprintf( ‘ ‘ . __(‘Required fields are marked %s’), ‘<span class=”required”>*</span>’ );这句的前面,添加一行内容:$content_me = cs_print_smilies2(); 接着在第1534行,也就是’comment_field’ => ‘<p class=”comment-form-comment”>……这行,替换成

‘comment_field’ => ’<p class=“comment-form-comment”><label for=“comment”>’ . _x( ’Comment’, ’noun’ ) . ’</label><br>’.$content_me.’<textarea id=“comment” name=“comment” cols=“45″ rows=“8″ aria-required=“true”></textarea></p>’, 

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

Tags: Wordpress custom-smilies 表情位置

分享到: