小站上一直使用Google Syntax Highlighter for WordPress 插件实现代码高亮,就在上一篇文章发布之后,我发现了这个插件中存在的一个bug:windows + IE 8无法正常加亮python代码。
查阅了官方网站,发掘Google Syntax Highlighter for WordPress插件用的1.5版已经停止更新,只能使用2.0以上的版本,但2.0版本和之前的版本又存在兼容的问题,直接替换是不行的。不想每篇文章的修改<pre>标记,那就改插件喽。
- 下载最新版本的Syntax Highlighter,解压。
- 将原来/wp-content/plugins/google-syntax-highlighter目录下的Scripts和Styles目录清空后,分别用新版本的对应路径中的文件替换,注意大小写方式请不要变动。
- 修改google_syntax_highlighter.php文件,我用了minify的插件,这里就直接调用了。
<?php
function insert_header() {
$current_path = get_option('siteurl') .'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/';
?>
<link href="<?php echo $current_path; ?>Styles/shCore.css" type="text/css" rel="stylesheet" />
//可根据自己的需要选择不同的Styles
<link href="<?php echo $current_path; ?>Styles/shThemeEclipse.css" type="text/css" rel="stylesheet" />
<?php
}
function insert_footer(){
$current_path = 'wp-content/plugins/' . basename(dirname(__FILE__)) .'/';
?>
<?php
/*
<script src="<?php echo $current_path; ?>Scripts/shCore.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shLegacy.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushCSharp.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushPhp.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushJScript.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushJava.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushVb.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushSql.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushXml.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushDelphi.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushPython.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushRuby.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushCss.js"></script>
<script src="<?php echo $current_path; ?>Scripts/shBrushCpp.js"></script>
*/
<script src="/wp-content/plugins/wp-minify/min/?b=<?php echo $current_path; ?>Scripts&f=shCore.js,shLegacy.js,shBrushPhp.js,shBrushSql.js,shBrushPython.js"></script>
<script>
dp.SyntaxHighlighter.ClipboardSwf = '<?php echo $current_path; ?>Scripts/clipboard.swf';
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
<?php
}
add_action('wp_head','insert_header');
add_action('wp_footer','insert_footer');
?>
测试,通过!
| anyShare分享到: | |
| |

#1 by saber on 2011年09月17日 - 00:19
你好,请问你的主页最下面的统计和社交网站的分享,是用什么插件实现的呢?wordpress新手~
#2 by Litrin on 2011年09月17日 - 12:06
社交网站的分享我用的是wordpress的aynshare插件,很简单,很方便。
页面底部的统计,我用的是自己通过Sina app写的一个小工具,只要在页面的适当位置嵌入
就可以用了。