WP-Syntax篇
wp-syntax是wordpress中比较流行的一款代码格式化插件,使用这款插件可以让需要展示的代码拥有独特的风格,使得整体页面浏览起来舒适,此外,这款插件整体简洁,消耗资源少,启动后对wordpress速度几乎没有影响。
效果如何?看看下面代码就知道了
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
下载地址:
WordPress官方下载
安装&使用:
安装方法:.下载插件→.上传插件到pluins目录下→.WP控制台→.插件→.激活插件
使用方法:1.编辑你当前使用的wordpress主题的CSS,加入以下内容:
{color: #100;
background-color: #f9f9f9;
border: 1px solid silver;
margin: 0 0 1.5em 0;
overflow: auto;
}/* IE FIX */
.wp_syntax {
overflow-x: auto;
overflow-y: hidden;
padding-bottom: expression(this.scrollWidth >
this.offsetWidth ? 15 : 0);
width: 100%;
}
.wp_syntax table {
border-collapse: collapse;
}
.wp_syntax div, .wp_syntax td {
vertical-align: top;
padding: 2px 4px;
}
.wp_syntax .line_numbers {
text-align: right;
background-color: #def;
color: gray;
overflow: visible;
}
/* potential overrides for other styles */
.wp_syntax pre {
margin: 0;
width: auto;
float: none;
clear: none;
overflow: visible;
}
2.在代码内容头和尾加入代码即可,形如
代码< /pre>
最后在使用的过程中注意 lang=”" 一定要使用双引号,而不能用单引号。
代码中的参数说明:
lang – 代码语言有针对性对代码进行高亮,可以是php,css。。。等等.
line – 默认值0—不显示代码行数,1为显示代码行数
Supported Languages(支持的语言)
The following languages are supported in the lang attribute:
abap, actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gml, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, m68k, matlab, mirc, mpasm, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, per, perl, php-brief, php, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80(Bold languages just highlight the more popular ones.)
Styling Guidelines
WP-Syntax uses default GeSHi colors by default. It also uses inline styling to make sure that code highlights still work in RSS feeds. To spruce up your code snippets to look more like the screenshots, try adding this CSS to your stylesheet template:
WP-Syntax 能够保留代码中的缩进(空格),让代码更加美观。不过,WP-Syntax高亮的代码默认不会进行拆行,如果代码过长的话,将会导致页面被撑大,影响美观。将如下 CSS 样式写入到所选择的主题样式中,能够解决这个问题: