升级到WP3.3后,之前的那些插入代码按钮都没有用啦。。上去找插件没找到,自己改了一个syntanx-highlighter的。
感谢原作者leo108,http://leo108.com/
把下面的代码保存下来,放在一个文件夹里,打包成zip文件,然后就可以在插件处上传安装了。
或者下载这个文件:http://fatkun.googlecode.com/files/wp-syntax-editor.zip
<?php
/*
Plugin Name: WP-Syntax Code Editor
Plugin URI: http://fatkun.com/2012/01/wp-syntax-code-editor.html
Description: 在编辑框加入一个插入wp-syntax代码的按钮,修改自syntax-highlighter-with-add-button-in-editor(原作者leo108)
Version: 1.0.0
Original Author: leo108
Author URI: http://fatkun.com/
*/
function codebox_init(){
?>
<div id="codebox" class="meta-box-sortables ui-sortable" style="position: relative;"><div class="postbox">
<div class="handlediv" title="Click to toggle"></div>
<h3 class="hndle"><span>WP-Syntax</span></h3>
<div class="inside">
Language:
<select id="language">
<option value="other">Other</option>
<option value="bash">Bash</option>
<option value="c">C</option>
<option value="cpp">C++</option>
<option value="csharp">C#</option>
<option value="css">CSS</option>
<option value="delphi">Delphi</option>
<option value="diff">Diff</option>
<option value="erl">Erlang</option>
<option value="groovy">Groovy</option>
<option value="html">HTML</option>
<option value="java">Java</option>
<option value="js">Javascript</option>
<option value="perl">Perl</option>
<option value="php">PHP</option>
<option value="ps">PowerShell</option>
<option value="python">Python</option>
<option value="ruby">Ruby</option>
<option value="sql">SQL</option>
<option value="vb">VisualBasic</option>
<option value="vb">VB.NET</option>
<option value="xml">XML</option>
</select>
<br>
Code:<br><textarea id="code" rows="8" cols="70" style="width:97%;"></textarea><br>
<input type="button" value="INSERT" onclick="javascript:settext();">
<script>
function settext()
{
var str='<pre escaped="true" lang="';
var lang=document.getElementById("language").value;
var code=document.getElementById("code").value;
str=str+lang;
str=str+'">';
str=str+filter(code)+"</pre>";
var win = window.dialogArguments ¦¦ opener ¦¦ parent ¦¦ top;
win.send_to_editor(str);
document.getElementById("code").value="";
}
function filter (str) {
str = str.replace(/&/g, '&');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
str = str.replace(/'/g, ''');
str = str.replace(/"/g, '"');
str = str.replace(/\¦/g, '¦');
return str;
}
</script>
</div></div></div>
<script>document.getElementById("postdivrich").appendChild(document.getElementById("codebox"));</script>
<?php
}
add_action('dbx_post_sidebar','codebox_init');
?>